Cash Register

So we have to make a cash register for my programming class and I keep having a round off error. Can anyone help me fix my code. And for some reason the math is wrong. Please 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  
// Cash Register Project; Per.5
// Sept. 8, 2015

#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>


using namespace std;

int main()
{
	
	string name;
	
	int total_price = 0;
	
	int user_input;
	
	cout << "Welcome to your very own cash register!" << endl;
	cout << "Enter your name." << endl;
	cin >> name;

	cout << "Hello, " << name << "." << endl;
	
	int itemx = 1;
	double cust_money;
	double pricex;
	int quantity;
	
	cout << "What's the price of the item " << itemx << "?" << endl;
	cin >> pricex;
	cout << "How many does the customer have?" << endl;
	cin >> quantity;

	cout << fixed << setprecision(2);

	cout << "Does the customer have another item? (enter 1 for yes or 0 for no)" << endl;
	cin >> user_input;

	while (user_input == 1)
	{

		itemx++;

		cout << "What is the price of item " << itemx << "?" << endl;
		cin >> pricex;
		cout << "How many does the customer have?" << endl;
		cin >> quantity;

		 total_price = total_price + (pricex * quantity);

		cout << "Does the customer have another item? (enter 1 for yes or 0 for no)" << endl;
		cin >> user_input;

	}

	cout << "Your customer's total is " << total_price << "." << endl;
	cout << "How much did the customer pay you?" << endl;
	cin >> cust_money;

	cout << fixed << setprecision(2);
	int change = (cust_money - total_price);

	cout << "The customer's change is " << change << "." << endl;
	cout << "Please hand them back:" << endl;

	int twenty = change / 100;

	int ten = change / 100;

	int five = change / 100;

	int one = change / 100;
	
	int quarters = change % 100;

	int dimes = change % 10;

	int nickels = change % 5;

	int pennies = change % 1;

	cout << " " << twenty << "twenty dollar bills." << endl;
	cout << " " << ten << "ten dollar bills." << endl;
	cout << " " << five << "five dollar bills." <<  endl;
	cout << " " << one << "one dollar bills." << endl;
	cout << " " << quarters << "quarters." << endl;
	cout << " " << dimes << "dimes." << endl;
	cout << " " << nickels << "nickels." << endl;
	cout << " " << pennies << "pennies." << endl;

	return 0;
}
Last edited on
Topic archived. No new replies allowed.