View Full Version : Damn c++ class, help!!!

09-07-2001, 01:25 PM
This has been bothering me, the teacher told me to make a cash register type program that you enter the total price of stuff and how much the person paid and it tells you how many 20s 10s 5s 1s quarters dimes nickels and pennies to give as change. I thought oh thats f#cking easy so I started to make it. I see no reason why my code doesnt work and like me and 2 other kids are the only ones who he assigned it to because were the only ones way ahead. They cant figure out why it wont work either. I dont have the source code here right now but it as something like this:

float change;
float cash_they_gave;
float TotalPrice;
int twentys, tens, fives, ones, quarters, dimes, nickels;

change = cash_they_gave - TotalPrice;

change -= 20;

change -= 10;


it compiles and but doesnt give me the right numbers.
please help and not turn my post pink.

09-07-2001, 01:51 PM
that should be

while(change >= 0) {
change -= 20;
if (change < 0)
change += 20;

It might be easier to use integer division along with finding
the remainder.

09-07-2001, 01:53 PM
Another option would be to use the search feature to find the other 3000 posts asking the exact same question.

09-07-2001, 01:58 PM
My fault that code won't work.

if (change < 0) {
change += 20;

You should just use division and remainder.