Hello! I am very NEW to programming this is my second week in my C++ class and I am having trouble with a part of my assignment.
The assignment:
"Write a program that asks the user for an amount of money (entered in cents) and then tells the user how to make change for that amount using only quarters, dimes, nickels, and pennies. Use the strategy used in lesson 2 part 3 (i.e., you must use the modulus operator* hint see Chapter 2.15 pg 62-64), and format your output exactly as in this sample screen output."
Please enter number of cents: 119
Change displayed in ascending order
-------------------------------
pennies: 4
nickels: 1
dimes: 1
quarters: 4
Change displayed in descending order
--------------------------------
quarters: 4
dimes: 1
nickels: 1
pennies: 4
While my code does build it's not exactly what the assignment is looking for.
Help. please and thank you :(
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
using namespace std;
int main()
{
double x;
int y;
cout << " Please enter number of cents: " << endl;
cin >> x;
y = x*100;
cout << "\n Change displayed in ascending order \n" << endl;
cout << "------------------------------------------" << endl;
cout << "\n Pennies:" <<y/1 << " ";
y=y%1;
cout << "\n Nickels: " << y/5 << " " ;
y=y%5;
cout << "\n Dimes: " << y/10 << " " ;
y=y%10;
cout << "\n Quarters: " << y/25 << " " ;
cout << "\n" <<endl;
cout << "\n Change displayed in descending order\n" <<endl;
cout << "\n--------------------------------------\n" <<endl;
cout << "\n Quarters:" <<y/25 << " ";
y=y%5;
cout << "\n Dimes: " << y/10 << " " ;
y=y%10;
cout << "\n Nickels: " << y/5 << " " ;
y=y%5;
cout << "\n Pennies: " << y/1 << " " ;
return 0;
}
|