Hey I was having some trouble on this code that requires me to write a program where a certain amount of money is input and what prints to the screen is the amount of money put in split into fifties, twenties, tens, fives, toonies, loonies, quarters, dimes, nickels and pennies. I am trying to write the program with the use of 'if' statements.
For example, 1567 (in cents) should print: 1567 cents requires 1 ten dollar bill, 1 five dollar bill, 2 quarters, 1 dime, 1 nickel, 2 pennies.
I can't seem to get the program to work correctly and would greatly appreciate some help. Thanks if you can help!
if you are using borland compiler it does not support system("pause"); it supports getch(); and if you are using devcpp then it supports int main() not void.
And also check the braces { } before the if statements and remove them.
please give me a day or two i will examine the codes and give u reply.
You have to improve the logic a bit.
Like the section for $50. You have
1 2 3 4 5
{
if (Amount >= 5000)
if (Amount < 10000)
cout<< "1 fifty dollar bill, " <<endl;
}
Try something more along this line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int fifty=0,twenty=0,..;//and a variable for each currency amount
{
int Amount=12567, fifty=0,twenty=0; // Oops, didn't mean to duplicate the variables. Already initialized to zero, above
while (Amount >= 5000)
{
fifty++;
Amount-=5000;
};
if(fifty>0) // Only prints next line IF you have 1 or more fifty dollar bills
cout << "You get " << fifty << " Fifty dollar bills." << endl;
while (Amount >= 2000)
{
twenty++;
Amount-=2000;
};
if (twenty>0) // Only prints next line IF you have 1 or more twenty dollar bills
cout << "You get " << twenty << " Twenty dollar bills." << endl;
// ----etc. with the rest
Very good program. I use Microsoft Visual C++ 2008 Express. So far, don't feel like upgrading to newer version. So, how's this program coming along now?
Its pretty good the program works and more importantly, I know how it works! I mean the code but a lot of the tools and functions in Microsoft Visual C++ 2010 Express I don't even get. I basically only use the build and the run button.