Help me please

This is a program to determine the fewest of each money denomination required to make change.
I'm stuck in the last part, I can't display correctly, the amount of nickels and pennies.

Please help me to fix my problem or if there is a way to improve it.
Thanks.

Input: Total amount of cents given by an user
Output: User's amount of cents converted in change using the fewest of each money denomination.

example: 299 cents

2 Dollars
1 Half Dollars
1 Quarter
2 Dimes
4 Pennies

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
#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;
int main()
{
string name;
double Total_amount_of_money, Remainder;

double const One_Dollar = 100, Dollarv = 1, HDollarv = .50, Quarterv = .25, Dimev = .10, Nickelv = .05, Pennyv = .01;
int Total_amount_of_cents, Dollars, Half_Dollars, Quarters, Dimes, Nickels, Pennies;
cout << "This is a program to determine the fewest of each money denomination required\nto make change.\n";
cout << endl;
cout << "Please enter your name:  ";
cin >> name;
cout << endl;   
cout << "Hello," << name << ". Please enter your total amount of cents: ";
cin >> Total_amount_of_cents;
cout << endl;
cout << Total_amount_of_cents << " cents is equal to: ";
cout << endl;
Dollars = Total_amount_of_cents / One_Dollar;
cout << "Dollars: " <<Dollars;
cout << endl;
Remainder = ((Total_amount_of_cents / One_Dollar) - Dollars);
Half_Dollars = (Remainder / HDollarv);
cout << "Half Dollars: " <<Half_Dollars;
cout << endl;
Quarters = ((Remainder - HDollarv) / Quarterv);

cout << "Quarters: " <<Quarters;
cout << endl;

Dimes = (((Remainder - HDollarv) - Quarterv) / Dimev);

cout << "Dimes: " <<Dimes;
cout << endl;
Nickels = ((((Remainder - HDollarv) - Quarterv) - Dimev) / Nickelv);

cout << "Nickels: " <<Nickels;
cout << endl;
Pennies = ((Remainder - HDollarv - Quarterv - Dimev - Nickelv) / Pennyv);
cout << "Pennies: " <<Pennies;

}

Last edited on
C:\c.cpp: In function `int main()':
C:\c.cpp:22: warning: converting to `int' from `double'
C:\c.cpp:26: warning: converting to `int' from `double'
C:\c.cpp:29: warning: converting to `int' from `double'
C:\c.cpp:34: warning: converting to `int' from `double'
C:\c.cpp:38: warning: converting to `int' from `double'
C:\c.cpp:42: warning: converting to `int' from `double'
Linking console executable: C:\c.exe
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 6 warnings
pass
without " #include "stdafx.h" "
Last edited on
Hi...,
As your code states the Remainder value is always "0".

1
2
3
4
Dollars = Total_amount_of_cents / One_Dollar;
....
....
Remainder = ((Total_amount_of_cents / One_Dollar) - Dollars);


Please focus into above lines of code.

Also if possible give one or two use cases, so that it is easier to analyze.
i.e. what is ur input and what are the expected output and current output.
Topic archived. No new replies allowed.