question about the end of my code

Write your question here.
I cannot figure out why my code is giving me a negative amount of tender due at the end of the program... can anyone 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
  #include <iostream>

#include <iomanip>
using namespace std;
void showMenu();

void displayBill(float bill, float totalBill, float& tip, float& taxDue);

void displayChange(float amtTendered, float amtChangeDue);

float bill, totalBill, amtTendered, amtChangeDue, taxDue, tipDue;

int main()

{
	//constants for menu items

	const int hamburgerPrice = 6;

	const float hotdogPrice = 4.5;

	const float peanutsPrice = 3.75;

	const float popcornPrice = 5.5;

	const float sodaPrice = 2.8;

	const int chipsPrice = 1;

	const int waterPrice = 2;

	//tax constant

	const float tax = 0.054;

	const float tip = 0.20;

	//total variables

	char menuChoice;

	float bill = 0;

	void showMenu();

	{

		cout << "Baseball Game Snack Menu" << endl;

		cout << "1 - hamburger    $6.00" << endl;

		cout << "2 - Hotdog       $4.50" << endl;

		cout << "3-  Peanuts      $3.75" << endl;

		cout << "4 - Popcorn      $5.50" << endl;

		cout << "5 - Soda         $2.80" << endl;

		cout << "6 - Chips        $1.00" << endl;

		cout << "7 - Water        $2.00" << endl;

		cout << "8 - END ORDER" << endl;

	}



	cout << "Enter menu item: \n";

	cin >> menuChoice;

	do
	{
		switch (menuChoice)
		{

		case '1':

			bill = bill + hamburgerPrice;

			cout << "Enter menu item: \n";

			cin >> menuChoice;
			break;
		case '2':
			bill = bill + hotdogPrice;
			cout << "Enter menu item: \n";

			cin >> menuChoice;

			break;

		case '3':

			bill = bill + peanutsPrice;

			cout << "Enter menu item: \n";

			cin >> menuChoice;

			break;

		case '4':

			bill = bill + popcornPrice;

			cout << "Enter menu item: \n";

			cin >> menuChoice;

			break;

		case '5':

			bill = bill + sodaPrice;

			cout << "Enter menu item: \n";

			cin >> menuChoice;

			break;

		case '6':

			bill = bill + chipsPrice;
			cout << "Enter menu item: \n";

			cin >> menuChoice;

			break;

		case '7':

			bill = bill + waterPrice;

			cout << "Enter menu item: \n";

			cin >> menuChoice;

			break;
		case '8':

			exit(0);

		default:

			cout << "You did not enter a menu item! (1-8):";

			cin >> menuChoice;

			break;
		}
	} while (menuChoice < '8');

	void displayBill(float& bill, float totalBill, float& tip, float taxDue);
	{

		float taxDue = bill * tax;

		float tipDue = bill * tip;

		float totalBill = bill + taxDue + tipDue;8

		cout << setprecision(3) << "Bill = $" << bill << endl;

		cout << "Tax = " << taxDue << endl;

		cout << "Tip = " << tipDue << endl;

		cout << setprecision(3) << "Total amount due: $" << totalBill << endl;

	}
	void displayChange(float& amtTendered, float amtChangeDue);
	{

		cout << "Enter Amount Tendered: " << endl;
		cin >> amtTendered;

		if (amtTendered < (bill + tip + tax))

		{
	cout << "Please enter enough to cover total bill" << endl;

			cin >> amtTendered;
		}

		else

		{
			amtChangeDue = totalBill - amtTendered;
			cout << "Change Due: $" << amtChangeDue << endl;
		}
	}
	system("pause");
		return 0;
}
Last edited on
You mean this?
amtChangeDue = totalBill - amtTendered;

What was the totalBill value, and what was the amtTendered value?

If amtTendered is bigger than totalBill , it seems pretty obvious why amtChangeDue is negative; if you have a number, and you subtract from it a bigger number, the result is negative.
Last edited on
Registered users can post here. Sign in or register to post.