Programming Assignment: Making change

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;
}
Last edited on
Here is how I would go about it:

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>

using namespace std;

int main()
{

	int money, quarters, dimes, nickles, pennies;

	cout << "Please enter the number of cents you want coins for: ";
	cin >> money;

	//find number of quarters
	quarters = money / 25;
	money = money % 25;

	//fin number of dimes
	dimes = money / 10;
	money = money % 10;

	//find number of nickles
	nickles = money / 5;
	money = money % 5;

	//find number of pennies
	pennies = money;


	//output results
	cout << "Change displayed in ascending order" << endl;
	cout << "-------------------------------" << endl;
	cout << "pennies: " << pennies << endl;
	cout << "nickels : " << nickles << endl;
	cout << "dimes : " << dimes << endl;
	cout << "quarters : " << quarters << endl;
	cout << "Change displayed in descending order" << endl;
	cout << "-------------------------------" << endl;
	cout << "quarters : " << quarters << endl;
	cout << "dimes : " << dimes << endl;
	cout << "nickels : " << nickles << endl;
	cout << "pennies: " << pennies << endl;




	return 0;
}

//code output
/*
Please enter the number of cents you want coins for: 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
Press any key to continue . . .
*/
Last edited on
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH JOE!!!!!!!!!!!!!!!!!! That's way easier! THANK YOU SO MUCH JOE!!!! Much appreciated!:)
Topic archived. No new replies allowed.