This program is supposed to enter the total, enter the amount the customer paid, calculate the change and tell how many dollars, quartes, nickels and pennies. The program has an error when I tried to calculate the total=5.67 and the amount paid=15.00 the change=9.39 Now Dollars=9, quarters=1,dimes=0, nickels=1,now her is the problem it gives me pennies=2 instead of pennies=3 This is what I Have and what do I have to change.
#include <iostream.h>
#include <stdlib.h>
usingnamespace std;
int main()
{
float total, amount_paid, change;
int dollar, quarters, dimes, nickels,pennies,choice;
char ch;
do{
cout<<endl;
cout<<"\t Welcome to Qcc Cafeteria Program"<<endl;
cout<<endl;
cout<<"Please choose the following: \n";
cout<<"\t1. Qcc Cafeteria Management. \n";
cout<<endl;
cout<<"Your choice: ";
cin>>choice;
cout<<"Enter the amount of the Check: $"; //Get the cost.
cin>>total;
cout<<"Enter the amount the customer paid: $"; //Get the amount to be paid.
cin>>amount_paid;
if(amount_paid<total){
cout<<endl;
cout<<"The customer owns more than that!"<<endl;
}
cout<<endl;
change = amount_paid - total;
cout<<"The change is: $"<<change<<endl;
dollar = (int) change; //Determine dollar bills integer part of the change.
cout<<"Number of Dollars Bills: "<<dollar<<endl;
change = change - dollar; //Take off the dollars and determine the quarters.
quarters = (int) (change*100)/25; //Multiply by 100 to convert cent's from dollars.
cout<<"Number of Quarters: "<<quarters<<endl;
change = change - quarters * (0.25); //Take off the quarters and determine the dimes.
dimes = (int) (change*100)/10;
cout<<"Number of Dimes: "<<dimes<<endl;
change = change - dimes * (0.10);//Take off the dimes and determine the nickels.
nickels = (int) (change*100)/5;
cout<<"Number of Nickels: "<<nickels<<endl;
change = change - nickels * (0.05); //Take off the nickels and determine the pennies.
pennies = (int) (change*100)/1;
cout<<"Number of Pennies: "<<pennies<<endl;
cout<<"\nWould you like to try again (y/n): ";
cin>>ch;
}while(ch == 'y' || ch == 'Y');
system("PAUSE");
return EXIT_SUCCESS;
}