Function returning to main

My program is almost done. However, when trying the second and third option the program returns to the main menu instead of calling the next function. The only function working properly is the cashier, and that is because it does not open another function, it keeps using a loop or exiting the program.

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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
  


#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <cstdlib>

using namespace std;

//prototypes
void mMenu();
void cashier();
void invmenu();
void report();
void bookInfo();

//inventory function prototypes
void lookUpBook();
void addBook();
void editBook();
void deleteBook();


#include "mainmenu.h"

using namespace std;

int main()
{
	mMenu();
}

void mMenu()
	{

		int choice;

		do{
			//display the menu and get a choice
			cout << "\t\t\tSerendipity Booksellers\n" << endl;
			cout << "\t\t\t\tMain Menu\n\n" << endl;
			cout << "1. Cashier Module\n" << endl;
			cout << "2. Inventory Database Module\n" << endl;
			cout << "3. Report Module\n" << endl;
			cout << "4. Exit \n\n" << endl;

			cout << "Enter Your Choice: \n" << endl;
			cin >> choice;

			while (choice <= 0 || choice > 4)
			{
				cout << "Please enter a number in the range 1-4 " << endl;

				cout << "Enter Your Choice: \n" << endl;
				cin >> choice;
			}

			//respond to the user's selection
			switch (choice){
			case 1: cashier();
				break;
			case 2: invmenu();
				break;
			case 3: report();
				break;
			case 4:
				cout << "Bye, bye!!!" << endl;
				break;
			}

		} while (choice != 4);

		system("Pause");


	}

	void cashier()
	{

		int option;
		string date;
		int bQuantity;
		string isbn;
		string bTitle;
		float bPrice;
		double total = 0.0;
		double tax = 0;
		double subtotal = 0.0;

		//constant 
		const double YES_OPTION = 1,
			NO_OPTION = 2;

		cout << "What is the date(MM/DD/YY): " << endl;
		cin >> date;
		cout << "\n" << endl;
		cout << "Number of books purchased: " << endl;
		cin >> bQuantity;
		cout << "\n" << endl;
		cout << "ISBN number: " << endl;
		cin >> isbn;
		cout << "\n" << endl;
		cout << "Title of book: " << endl;
		cin >> bTitle;
		cout << "\n" << endl;
		cout << "Cost of book: " << endl;
		cin >> bPrice;
		cout << " \n\n" << endl;

		//display information to the user
		cout << "Serendipity Booksellers\n" << endl;
		cout << "\tCashier Module\n\n" << endl;
		cout << "Date: " << date << " \n" << endl;
		cout << "Quantity of Book " << bQuantity << "\n" << endl;
		cout << "ISBN " << isbn << " \n" << endl;
		cout << "Title: " << bTitle << "\n" << endl;
		cout << "Price: $" << bPrice << "\n\n\n" << endl;

		//calculations
		subtotal = (bQuantity*bPrice);

		tax = (bQuantity*bPrice)*0.06;

		total = subtotal + tax;

		//display final window with all the info
		cout << "Serendipity Book Sellers\n\n " << endl;
		cout << "Date: " << date << endl;
		cout << "\nQty		ISBN		Title		Price		Total\n\n" << endl;
		cout << "________________________________________________________\n\n\n" << endl;
		cout << " " << bQuantity << " \t\t" << isbn << "\t" << bTitle << "\t\t$" << bPrice << "\t\t$" << subtotal << endl;
		cout << "		\n\n\tSubtotal: " << "\t\t\t\t\t\t$" << subtotal << endl;
		cout << "			\n\tTax: " << "\t\t\t\t\t\t\t$" << tax << endl;
		cout << "			\n\tTotal: " << "\t\t\t\t\t\t\t$" << total << endl;

		cout << "\n\nThank You for Shopping at Serendipity!\n\n" << endl;



		cout << "\t\tAnother transaction?" << endl;
		cout << "\t\t1. Yes" << endl;
		cout << "\t\t2. No\n" << endl;
		cin >> option;

		if (option == YES_OPTION)
		{
			cashier();
		}
		else if (option == NO_OPTION)
		{
			cout << "\nPlease come again!!" << endl;
		}


		cin.get();

	}

	void invmenu()

	{
		int choice1;

		do {//display the menu
			cout << "\t\t\tSerendipity Booksellers\n" << endl;

			cout << "\t\t\tInventory Database\n" << endl;

			cout << "\n\t\t\t1. Look Up a Book" << endl;

			cout << "\n\t\t\t2. Add a Book" << endl;

			cout << "\n\t\t\t3. Edit a Book's Record" << endl;

			cout << "\n\t\t\t4. Delete a Book" << endl;

			cout << "\n\t\t\t5. Return to the main menu" << endl;

			cout << "\n\t\t\tEnter Your Choice: \n " << endl;

			cout << "Enter Your Choice: \n" << endl;
			cin >> choice1;

			while (choice1 <= 0 || choice1 > 5)
			{
				cout << "Please enter a number in the range 1-5 " << endl;

				cout << "Enter Your Choice: \n" << endl;
				cin >> choice1;
			}


			//respond to the user's selection
			switch (choice1){
			case 1: lookUpBook();
				break;
			case 2: addBook();
				break;
			case 3: editBook();
				break;
			case 4: deleteBook();
				break;
			case 5: mMenu();
				break;
			}

		} while (choice1 = !5);
		cin.get();


	}

	void lookUpBook()
	{

		cout << "You selected look up a book" << endl;
	}

	void addBook()
	{

		cout << "You selected add a book" << endl;
	}

	void editBook()
	{
		cout << "You selected edit a book" << endl;
	}

	void deleteBook()
	{
		cout << "You selected delete a book" << endl;
	}





	void bookInfo()
	{


		cout << "\t\t\tSerendipity Booksellers\n" << endl;
		cout << "\t\t\t   Book Information \n" << endl;
		cout << "ISBN: \n" << endl;
		cout << "Title: \n" << endl;
		cout << "Author: \n" << endl;
		cout << "Publisher: \n" << endl;
		cout << "Date Added: \n" << endl;
		cout << "Quantity-On-Hand: \n" << endl;
		cout << "Wholesale Cost: \n" << endl;
		cout << "Retail Price: \n" << endl;

		cin.get();


	}

	void report()
	{

		int choice;

		//constants
		const double LIST_CHOICE = 1,
			WHOLESALE_CHOICE = 2,
			RETAIL_CHOICE = 3,
			QUANTITY_CHOICE = 4,
			COST_CHOICE = 5,
			AGE_CHOICE = 6,
			RETURN_CHOICE = 7;


		cout << "\t\t\tSerendipity Booksellers\n" << endl;

		cout << "\t\t\t     Reports \n" << endl;

		cout << "\t\t1. Inventory Listing \n" << endl;

		cout << "\t\t2. Inventory Wholesale Value \n" << endl;

		cout << "\t\t3. Inventory Retail Value \n" << endl;

		cout << "\t\t4. Inventory by Quantity \n" << endl;

		cout << "\t\t5. Inventory by Cost \n" << endl;

		cout << "\t\t6. Inventory by Age \n" << endl;

		cout << "\t\t7. Return to Main Menu \n" << endl;



		cout << "Enter Your Choice: " << endl;
		cin >> choice;

		while (choice <= 0 || choice > 7)
		{
			cout << "Please enter a number in the range 1-7\n " << endl;

			cout << "Enter Your Choice: " << endl;
			cin >> choice;
		}

		//respond to the user's selection

		if (choice == LIST_CHOICE)
		{
			cout << "Opening Inventory Lisitng\n" << endl;
		}
		else if (choice == WHOLESALE_CHOICE)
		{
			cout << "Opening Inventory Wholesale Value\n" << endl;
		}
		else if (choice == RETAIL_CHOICE)
		{
			cout << "Opening Inventory Retail Value\n" << endl;
		}
		else if (choice == QUANTITY_CHOICE)
		{
			cout << "Opening Inventory by Quantity\n" << endl;
		}
		else if (choice == COST_CHOICE)
		{
			cout << "Opening Inventory by Cost\n" << endl;
		}
		else if (choice == AGE_CHOICE)
		{
			cout << "Opening Inventory by Age\n" << endl;
		}
		else if (choice == RETURN_CHOICE)
		{
			cout << "Returning to the Main Menu\n" << endl;
		}


		cin.get();

	}


The bbook info function is not being used so it does not affecte the output
I just messed around with it a little. If you select "Inventory Database Module" it pulls up the inventory database as expected, but then all of the function calls from there do nothing but print a single line.

lookUpBook(), addBook(), editBook(), and deleteBook() do nothing but print a single string.


Is this as intended or did you forget to add function calls?

Same thing in report. The if block under the comment "respond to the user's selection" only prints out a single line.



EDIT: On an unrelated note, if this is your full code I don't think mainmenu.h is actually doing anything.
Last edited on
Topic archived. No new replies allowed.