Hey everyone. I have a question. I am working on Visual Basic Express and I am supposed to calculate the change from a transaction.
Now what code would I use? I have it partly working but its starting to get a little confusing.
Thank you.
For you guys who wanted more information:
Say I have one dollar and I go to the store to purchase something. I have to ask the user to put in the amount they spent and then calculate the change and print to the screen.
Then I am supposed to use the least number of quarters, dimes nickels and pennies and print it to screen.
Any help would be greatly appreciated.
I'm going to go out on a limb here and assume the OP is talking about change as in money returned from a transaction.
If that's the case, then it's probably homework, so pseudo-code only.
The simplest first-attempt way of doing it is as follows. Let
cost
be the cost of the transaction andtendered
be the amount of money handed over (both in cents), and let's further assume your economy only has dollar bills, quarters and pennies (to make my code smaller).Now this can no doubt be made more efficient with the use of modulo and divide operators but I leave that as an exercise for the reader.
My suggestion is to sit down with a pencil and a bit of paper with the following columns (for handing over ten dollars for a two-dollar-and-ninety-three cent purchase):
and run through the code line by line in your head, using the current values from the paper and writing down the new values where they change.
This will greatly assist your understanding.
In response to your update:
That's remarkably similar to what I had above: