Trouble with change

Hello guys. I'm new to here and sorta new to C++. This is the final program of the semester I have to write, and it mostly works, except for one thing. I'll mark the issues below.

float cheeseburger=3.95, chicken_sandwich=4.37, hot_dog=3.56, soda=1.57, fries=1.71, total, payment, tax, change, keep;//Setting costs here to make it easier

string username;
int check=1, choice, dollars, quarters, dimes, nickels, pennies;

//Input
cout<<"What's your name?\n";
getline (cin, username); //This acts as the cin statement for strings
system ("cls");
do
{
cout<<"Hello "<<username<<", and welcome to the All-American Concessions Stand!\n\n";

cout<<"What would you like to order?\n1.) Cheeseburger\t$3.95\n2.) Chicken Sandwich\t$4.37\n3.) Hot Dog\t\t$3.56\n4.) Soda\t\t$1.57\n5.) Fries\t\t$1.71\n6.) Quit\n";
total=0;
do
{
cin>>choice;
switch (choice)
{
case 1:
total=total+cheeseburger;
cout<<"Anything else?\n";
break;
case 2:
total=total+chicken_sandwich;
cout<<"Anything else?\n";
break;
case 3:
total=total+hot_dog;
cout<<"Anything else?\n";
break;
case 4:
total=total+soda;
cout<<"Anything else?\n";
break;
case 5:
total=total+fries;
cout<<"Anything else?\n";
break;
case 6:
break;
}
}
while (choice!=6);
cout<<"Your subtotal is $"<<total<<endl;
tax=total*.065;
total=total+tax;
cout<<"Your tax amount, "<<username<<", is $"<<fixed<<setprecision(2)<<tax<<endl;
cout<<"Your total is $"<<fixed<<setprecision(2)<<total<<endl;
cout<<"How much are you paying with, "<<username<<"? ";
cin>>payment;

do
{
if (total>payment)
{
cout<<"That's not enough! How much are you actually paying? ";
cin>>payment;
}
}
while (payment<total);

system ("cls");
change=payment-total;
keep=change;

//Change program

for (dollars=0; change>=1; dollars++)
{
change=change-1;
}

for (quarters=0; change>=0.25; quarters++)
{
change=change-0.25;
}

for (dimes=0; change>=0.1; dimes++)
{
change=change-0.1;
}

for (nickels=0; change>=0.05; nickels++)
{
change=change-0.05;
}

for (pennies=0; change>=0.01; pennies++)
{
change=change-0.01;
}


cout<<"Your change is $"<<keep<<", which can be made with:\n"<<dollars<<" dollar(s)\n"<<quarters<<" quarter(s)\n"<<dimes<<" dime(s)\n"<<nickels<<" nickel(s)\n"<<pennies<<" penny(s)\n\n";

cout<<"Do you want to repeat the program?\n1.)Yes\n2.)No\n\n";
cin>>check;
cout<<"Okay!\n";
system ("pause");
system ("cls");
}
while (check!=2);

cout<<"Thanks for ordering, "<<username<<", and have a nice day.\n";
system ("pause");
return 0;
}

---

The problem I'm facing is that whenever the user payment is equal to the total cost, the program thinks that the user is still not paying enough. Not just this, but if the user puts the payment amount to one cent greater than the cost, the change doesn't output one penny.

Any ideas why?
edit and use code tags pls
and I can't see the start of your program

after
1
2
change=payment-total;
keep=change;

and before
//Change program
cout all your values to see if they are correct.
Last edited on
There are a lot of undefined variables here.
For example, total, cheeseburger etc.
Are these of type int, float, double, etc? What are their initial values.
Topic archived. No new replies allowed.