How to fix this?


The output is, the selection is keep appearing. Also, I already put system("CLS"); in the case 0 then goto receipt. Why the selection is keep appearing?

Also, while putting the another quantity, the selection is keep appearing.

i put "meow meow meow", because i was still testing it.

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
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>

using namespace std;

int main()
{
		string customername, address, customertin;
        double lays = 1.1390, luxury = 1.9178, marshies = 0.2531;
        int choice, q1 = 0, q2 = 0, q3 = 0, q4 = 0, q5 = 0;
        double total, cash;


		cout << "Customer Name: ";
		getline(cin, customername);
	
		cout << "Customer Address: ";
		getline(cin, address);

	
		cout << "Customer TIN: ";
		getline(cin, customertin);

		
		system("CLS");

        while(true)
        {
        	
                cout << "Please make a selection" << endl << endl;
                cout << "Enter 1 for Lays Stax Sour Cream Onion 100g - $" << setprecision(4) << lays << endl;
                cout << "Enter 2 for Luxury Vegetable Chococream 200g - $" << luxury << endl;
                cout << "Enter 3 for Marshies Strawberry Style - $" << marshies << endl;
                cout << "Enter 4 to see what you owe" << endl;
                cout << "Enter 0 when you are done" << endl << endl;

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



                switch(choice)
                {
                case 1:
                        cout << "How many would you like to purchase?" << endl;
						cout << "Quantity: ";
						cin >> q1;
						cout << endl;
                        break;
                case 2:
                        cout << "How many would you like to purchase?" << endl;
						cout << "Quantity: ";
						cin >> q2;
						cout << endl;
                        break;
                case 3:
                        cout << "How many would you like to purchase?" << endl;
						cout << "Quantity: ";
						cin >> q3;
						cout << endl;
                        break;

                case 4:
						total = (q1*lays) + (q2*luxury) + (q3*marshies);
						
						cout << "Your total amount is: $" << total << endl;
                        break;
                        
                case 0:
						cout << "Enter your cash: ";
						cin >> cash;
						break;
						system("CLS");
						goto receipt;

					}
					
			receipt:
				cout << "meow meow meow " << endl;

        }

}
Last edited on
the selection is keep appearing.
The reason is line 76. The break will end the case and effectively skip the lines below. Line 78 goto receipt; is unnecessary.
Just a quick note, try not to use system("anything")
Here's an overview why:
http://www.cplusplus.com/articles/j3wTURfi/
Well, why the selection is keep appearing? because, what i want is, if putting the another product and quantity, i just want the question only. What is the code for that? Thanks


output:
Please make a selection

Enter 1 for Lays Stax Sour Cream Onion 100g - $1.139
Enter 2 for Luxury Vegetable Chococream 200g - $1.918
Enter 3 for Marshies Strawberry Style - $0.2531
Enter 4 to see what you owe
Enter 0 when you are done

Choice: 1

How many would you like to purchase?
Quantity: 2

meow meow meow
Please make a selection

Enter 1 for Lays Stax Sour Cream Onion 100g - $1.139
Enter 2 for Luxury Vegetable Chococream 200g - $1.918
Enter 3 for Marshies Strawberry Style - $0.2531
Enter 4 to see what you owe
Enter 0 when you are done

Choice: ,

i mean my expected output will be like this

expected output:

Please make a selection

Enter 1 for Lays Stax Sour Cream Onion 100g - $1.139
Enter 2 for Luxury Vegetable Chococream 200g - $1.918
Enter 3 for Marshies Strawberry Style - $0.2531
Enter 4 to see what you owe
Enter 0 when you are done

Choice: 1

How many would you like to purchase?
Quantity: 2

Choice: 2


How many would you like to purchase?
Quantity: 2
Move lines 32 to 37 above the while loop (line 29).
Topic archived. No new replies allowed.