So I'm supposed to 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
using namespace std;
int main() {
int amount;
cout << "Enter amount of dollars. ";
cin >> amount;
int twenties, tens, fives, singles;
amount = 137;
137 / 20 = 6 twenties; the remainder 137 % 20 = 17;
17 / 10 = 1 tens; the remainder 17 % 10 = 7;
7 / 5 = 1 fives; the remainder amount 7 % 5 = 2;
cout << "For the amount of ">> amount >> "we need ">> twenties, tens, fives, singles;
return 0;
}
|
Please tell me what I am doing wrong. Thank you