Loop Menu

Hello, newbie here and had a few questions if anyone could help. Currently not finished, case3 can be ignored. So right now everything is working fine sort of except right now I'm receiving an error if do not make a selection. Ex: I select fuzzy dice, it loops, then select 4 to exit. I get an error for not having a value for BeadTotal since it is unused. How could I solve this?
Second I also have to make it so negative Amount#'s are invalid, how would I go about doing this. Thanks!

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
	cout << "Welcome to DecoCar \n" << endl;
		do
		{
		cout << "Our inventory: \n";
		cout << "1. Fuzzy Dice \n"
			"2. Mardi Gras Beads \n"
			"3. Bobble Heads \n"
			"4. Exit \n" << endl;


		cout << "Please make a selection: ";
		cin >> choice;

		cout << setprecision(2) << fixed << endl;

		{
			switch (choice)
			{
			case 1:
				cout << "How many Fuzzy Dice would you like to buy? ";
				cin >> Amount1;
				DiceTotal = Amount1 * DICE;
				cout << "The subtotal for the fuzzy dice: $" << DiceTotal << endl << endl << endl;
				break;
			case 2:
				cout << "How many sets of Mardi Gras beads would you like to buy? ";
				cin >> Amount2;
				BeadTotal = Amount2 * BEADS;
				cout << "Please type in coupon code or NONE NONE \n";
				cin >> code;
				cout << "The subtotal for the beads(s): $" << BeadTotal << endl << endl << endl;
				break;
			//case 3:
				//break;
			case 4:
				Total = BeadTotal + DiceTotal;
				cout << "Thank you from ordering from DecoCar \n";
				cout << "Your Total Is: $" << Total << endl;
				break;
			default:
				cout << "Sorry we do not sell that item. \n";
				cout << "Please make another selection. \n" << endl;
				break;
			}
		}
	}
		while (choice != 4);
	
	system("pause");
		return 0;
	}
You can initialize your Amount1 and Amount2 to 0 from the start of the program.

One way to solve for the negative amounts would be to use the absolute value function: abs(choice), that way if they enter -1, for example, it would be counted as a postive 1.

Depends on how you want to do it exactly.
Hello Bettarun3,

Welcome to the forum.

I see the end of your program, but not the beginning. I would guess that BeadTotal along with DiceTotal and maybe some other variables were not initialized. Because of that you have no idea what the value of BeadTotal is and most likely an unusable value for total. If the compiler did not give you a warning about uninitialized variables then the run time error may b because the value of Total exceeds the variable type.

As to checking for a negative number you will have to check for that after your input. I would suggest using a function to get the input and then validate if it is a usable value. The function could take a string like in line 20 and 26 to tell the user what information is required.

Hope that helps,

Andy
Topic archived. No new replies allowed.