Here is my code. Again, should be very simple to solve my issue. I don't think just adding a cent would work because then it would be one cent over in some cases (say the user puts in 5.00.
Code:
#include <iostream>
using namespace std;
int main ()
{
float change = 0.0;
int toonies = 0;
int loonies = 0;
int quarters = 0;
int dimes = 0;
int nickel = 0;
int pennies = 0;
cout<<”How much change is to be returned? “;
cin>>change;
toonies=(change/2);
cout<<toonies<<” X $2.00”<<endl;
change=change-(toonies*2);
loonies=change;
cout<<loonies<<” X $1.00”<<endl;
change=change-loonies;
quarters=change/0.25;
cout<<quarters<<” X $0.25”<<endl;
cout=change-(quarters*0.25);
dimes=change/0.1;
cout<<dimes<<” X $0.10”<<endl;
change=change-(dimes*0.1);
nickel=change/0.05;
cout<<nickel<<” X $0.05”<<endl;
change=change-(nickel*0.05);
pennies=change/0.01;
cout<<pennies<<” X $0.01”<<endl;
return 0;
}
And when running the program this is what is outputted:
How much change is to be returned? (I enter 5.79)
2 X $2.00
1 X $1.00
3 X $0.25
0 X $0.10
0 X $0.05
3 X $0.01