Please help me complete the code for this task! Thank you in advance!
Write a program that reads an amount of dollars int amount. Then the program determines how many $20 bills, $10 bills, $5 dollar bills and $1 dollar bills are needed to represent the amount. Use four more variables int twenties, tens, fives, singles; for which you are to compute their respective values using integer division and remainder (operators / and % respectively.)For instance: say amount = 137. Then we need 137 / 20 = 6 twenties; the remainder 137 % 20 = 17.
17 / 10 = 1 tens; the remainder 17 % 10 = 7
7 / 5 = 1 fives; the remainder 7 % 5 = 2;
At this point the last remainder is 2 so that we need 2 singles.
The program should print the following line For the amount of $137 we need 6 twenties, 1 tens, 1 fives, and 2 singles.
You need to learn about variables, data types, and operators. The "Basics of C++" section in the C++ Language Tutorial on this site covers that. I recommend you read through that section. Here is the link: http://www.cplusplus.com/doc/tutorial/
To give you an idea, you will need to assign the results of integer division to the variables you've defined. For example, to get the number of twenties in amount, you can do this:
twenties = amount / 20;
You can use the modulus operator to get the remainder of amount divided by 20 in order to calculate the number of tens, and so on. This should replace lines 11 through 13 in your code.
Also, since you are asking the user to enter the amount at the console via the cin statement, you don't want to assign 137 to amount as you are doing in line 10.
Please read about the assignment operator (the equal sign) in the tutorial.
This is an assignment statement that stores the integer quotient of amount divided by 20:
twenties = amount / 20;
The above is correct. But this next statement doesn't assign anything, and it is incorrect:
twenties % 20;
Even if it was an assignment statement, you aren't dealing with the right values there. Think about how you are approaching it. The modulus operator gets the remainder of integer division. The value that was stored in variable twenties by the previous assignment statement is the number of 20's in amount. You don't need the remainder of that divided by 20. It is the remainder of amount divided by 20 that you need in order to get the number of 10's.
You can reuse the amount variable to hold the remainder before extracting the next monetary type.
I hesitate to say more than this because I believe you can figure it out if you would review the section in the tutorial on assignment statements and the division and modulus operators.