how to add money values

I try to add the value of dollars, quarters, dimes, nickels, pennys for the total monetary value but do not know how. Any help?

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
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string name;
	int dollar;
	float quarter, dime, nickel, penny;
	double total;


	


	 dollar = 1;
	 quarter = .25;
	dime = .1;
	 nickel = .05;
	penny = .01;



	// input servers name
	cout << "What is your name?";
		getline(cin, name);
	

	//input dollars made
		cout << "how many dollars did you receive";
		cin >> dollar; 
	

	// input quarters made
	cout << "Quarters received?";
	cin >> quarter;

	// input dimes
	cout << "dimes";
	cin >> dime;
	
	// input nickel 
	cout << "nickels?";
		cin >> nickel;

	// input penny
	cout << "pennies";
	cin >> penny;

	// input total
	total = dollar + quarter + dime + nickel + penny;
	cout <<total;


	system("PAUSE");
	return 0;

}
Last edited on
@TheArk

As I mentioned to you in a previous thread
http://www.cplusplus.com/forum/beginner/217188/
, you need another set of variables to hold the amount of coins received.

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
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string name;
	int dollar, dollar_received, quarter_received, dime_received, nickel_received, penny_received;
	double quarter, dime, nickel, penny;
	double total;

	dollar = 1;
	quarter = .25;
	dime = .1;
	nickel = .05;
	penny = .01;

	// input servers name
	cout << "What is your name?";
		getline(cin, name);
	
	//input dollars made
		cout << "how many dollars did you receive? ";
		cin >> dollar_received; 
	
	// input quarters made
	cout << "Quarters received? ";
	cin >> quarter_received;

	// input dimes
	cout << "dimes? ";
	cin >> dime_received;
	
	// input nickel 
	cout << "nickels? ";
		cin >> nickel_received;

	// input penny
	cout << "pennies? ";
	cin >> penny_received;

	// input total
	cout << "That ends up to equal ";
	total = (dollar*dollar_received) + (quarter*quarter_received) + (dime*dime_received) + (nickel*nickel_received) + (penny*penny_received);
	cout << "$" << total << endl;
	
	system("PAUSE");
	return 0;
}
Now I understand, I have changed my code accordingly, however the total is still adding up to an int, rather than a decimal, and the items aren't being multiplied

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
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string name;
	int dollar, dollarReceived, quarterReceived, dimeReceived, nickelReceived, pennyReceived;
    double quarter, dime, nickel, penny, 
		double total;
	


	


	 dollar = 1;
	 quarter = .25;
	dime = .1;
	 nickel = .05;
	penny = .01;



	// input servers name
	cout << "What is your name?";
		getline(cin, name);
	

	//input dollars made
		cout << "how many dollars did you receive";
		cin >> dollarReceived; 
	

	// input quarters made
	cout << "Quarters received?";
	cin >> quarterReceived;

	// input dimes
	cout << "dimes";
	cin >> dimeReceived;
	
	// input nickel 
	cout << "nickels?";
		cin >> nickelReceived;

	// input penny
	cout << "pennies";
	cin >> pennyReceived;

	// input total
	total = (dollar*dollarReceived) + (quarter*quarterReceived) + (dime*dimeReceived) + (nickel*nickelReceived) + (penny*pennyReceived);
	cout << "$" <<total << endl;


	system("PAUSE");
	return 0;

}
@TheArk

Maybe the values you're inputting, actually equals an even amount. Try making sure you use odd coin counts.

If that doesn't work, show me the values you are using, and I'll look over the code with those inputted.
I have run the program with value of 3 dollars, 3 quarters, 3 dimes, 3 nickels, 3 pennys, with the total coming to 15, so they are not multiplying properly... I am sure it is something obvious again, appreciate the help.
penny should have a ; after it instead of a ,

1
2
    double quarter, dime, nickel, penny, 
		double total;


But otherwise it looks like you're calculating correctly.
1
2
3
4
5
6
7
What is your name?joe
how many dollars did you receive3
Quarters received?3
dimes3
nickels?3
pennies3
$4.23
That did it, the semi colon after penny, I just overlooked it. Thanks!
Topic archived. No new replies allowed.