Ok. I'm stuck on another one. I really have no clue what i'm doing. I'm supposed to calculate the number of dollars,quarters,dimes,nickels and pennies that a user would receive if he cashed in the pennies at a bank.
I have:
Dim totalpennies, dollars, quarters, dimes, nickels, pennies As Integer
dollars = Convert.ToInt32(Me.uiDollarsTextBox.Text)
quarters = Convert.ToInt32(Me.uiQuartersTextBox.Text)
nickels = Convert.ToInt32(Me.uiNickelsTextBox.Text)
dimes = Convert.ToInt32(Me.uiDimesTextBox.Text)
pennies = Convert.ToInt32(Me.uiPenniesTextBox.Text)
totalpennies = (totalpennies Mod dollars) + (totalpennies Mod quarters) + (totalpennies Mod nickels) + (totalpennies Mod dimes) + (totalpennies Mod pennies)
When I run the application it tells me that "Input string was not in a correct format." Please help. I'm stuck.
I am using vb.net in a windows application.
3 Replies  15690 Views  Last Post: 27 September 2009  05:56 PM
Replies To: Change Calculator
#2
Re: Change Calculator
Posted 28 September 2005  11:54 AM
Perhaps I've misunderstood you...you say you need to input a number of pennies, and find out what the user would have in he traded up where possible. In that case, you only need two input boxes...one to take the total number of pennies, and one to display the results, plus one button to action it.
Using aform with TextBox1, button1 and TextBox2, I used this code for the button:
The logic is thus...take in the total number of pennies...using that as the start number, you see how many times 100 pennies goes into that to give you a dollar amount, then use the Int function to take off the decimal...for the next one  quarters  you take the remainder of what was left from the previous calculation, and do the same thing, all the way down the line.
It is very important that you understand exactly what is happening in this code...otherwise, you will not be able to solve similar problems...please ask if you have any questions.
Using aform with TextBox1, button1 and TextBox2, I used this code for the button:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim totalpennies As Integer totalpennies = Convert.ToInt32(Me.TextBox1.Text) Me.TextBox2.Text = Int((totalpennies / 100)) & " dollars, " & Int((totalpennies Mod 100) / 25) & " quarters, " & Int(((totalpennies Mod 100) Mod 25) / 10) & " dimes, " & Int((((totalpennies Mod 100) Mod 25) Mod 10) / 5) & " nickels and " & Int((((totalpennies Mod 100) Mod 25) Mod 10) Mod 5) & " pennies." End Sub
The logic is thus...take in the total number of pennies...using that as the start number, you see how many times 100 pennies goes into that to give you a dollar amount, then use the Int function to take off the decimal...for the next one  quarters  you take the remainder of what was left from the previous calculation, and do the same thing, all the way down the line.
It is very important that you understand exactly what is happening in this code...otherwise, you will not be able to solve similar problems...please ask if you have any questions.
#3
Re: Change Calculator
Posted 28 September 2005  12:11 PM
I was trying to break it up to have my results be in different text boxes depending on dollar,quarter,dime etc. but I was able to figure it out thanks to your example. I really appreciate it! Hopefully I'll figure this stuff out & wont have to bug you again.
This post has been edited by polishPrincess83: 28 September 2005  12:21 PM
#4
Re: Change Calculator
Posted 27 September 2009  05:56 PM
polishPrincess83, on 28 Sep, 2005  11:11 AM, said:
I was trying to break it up to have my results be in different text boxes depending on dollar,quarter,dime etc. but I was able to figure it out thanks to your example. I really appreciate it! Hopefully I'll figure this stuff out & wont have to bug you again.
Would you be kind enough to post a sample of this code?
Page 1 of 1
