The compiler stopped working

Hello guys. Do any of you know why my compiler stopped working when user try to input "Enter your choice based on the number" for the 2nd time. The 1st time it worked correctly. I got the correct output but for the 2nd time the compiler stopped. Is there anything wrong with my coding? Thanks in advance.

The output I must get:

Would you like to order a pizza [y/n]:
y
[1] - BBQ Chicken
[2] - Island Delight
[3] - Hawaiian Delight
Enter your choice based on the number:
2
You've selected Island Delight
Please enter size [R / L]:
L
Please enter quantity:
2
Thank you for ordering
----Your pizza details-----
Pizza : Island Delight
Quantity : 2
Price perpizza : RM 33.30
Total payment : RM 66.60
Would you like to order another pizza [y/n]:
y
[1] - BBQ Chicken
[2] - Island Delight
[3] - Hawaiian Delight
Enter your choice based on the number:
1
You've selected BBQ Chicken
Please enter size [R / L]:
r
Please enter quantity:
2
Thank you for ordering
----Your pizza details-----
Pizza : BBQ Chicken
Quantity : 2
Price perpizza : RM 25.00
Total payment : RM 50.00
Would you like to order another pizza [y/n]:
n
Press any key to continue

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
#include <iostream>
using namespace std;

class Pizza
{
private:
    string name;
    char size;
    int quantity;
    float price, totalprice;

public:
    int choice;

    void menu()
    {
        cout << "\n[1] - BBQ Chicken" << endl;
        cout << "[2] - Island Delight" << endl;
        cout << "[3] - Hawaiian Delight" << endl;
    }

    void setSelection()
    {
        cout << "\nEnter your choice based on the number: " << endl;
        cin >> choice;

        if (choice == 1)
        {
            name = "BBQ Chicken";
        }

        else if (choice == 2)
        {
            name = "Island Delight";
        }

        else
        {
            name = "Hawaiian Delight";
        }

    }

    void setSizeQuantity()
    {
        cout << "\nYou've selected " << name << endl;
        cout << "\nPlease enter size [R/L]" << endl;
        cin >> size;
        cout << "\nPlease enter quantity" << endl;
        cin >> quantity;

        if (choice == 1)
        {
            if (size == 'R')
            {
                price = 25.00;
                totalprice = quantity * price;
            }

            else
            {
                price = 35.30;
                totalprice = quantity * price;
            }
        }

        if (choice == 2)
        {
            if (size == 'R')
            {
                price = 22.00;
                totalprice = quantity * price;
            }

            else
            {
                price = 33.30;
                totalprice = quantity * price;
            }
        }

        if (choice == 3)
        {
            if (size == 'R')
            {
                price = 24.50;
                totalprice = quantity * price;
            }

            else
            {
                price = 36.60;
                totalprice = quantity * price;
            }
        }
    }

    void display()
    {
        cout << "\nThank You for ordering" << endl;
        cout << "\n----Your pizza details----" << endl;
        cout << "\nPizza : " << name << endl;
        cout << "\nQuantity : " << quantity << endl;
        cout << "\nPrice perpizza : RM " << price << endl;
        cout << "\nTotal Payment : RM " << totalprice << endl;
    }
};

int main()
{
    char user;

    Pizza *PizzaHut = new Pizza();

    cout << "\nWould you like to order a pizza [y/n]: " << endl;
    cin >> user;

    while (user == 'y')
    {
            if (user == 'y')
            {
               PizzaHut -> menu();
               PizzaHut -> setSelection();
               PizzaHut -> setSizeQuantity();
               PizzaHut -> display();

               delete PizzaHut;
            }

             cout << "\nWould you like to order a pizza [y/n]: " << endl;
             cin >> user;
    }
    return 0;
}
Could be because you delete your Pizza object before the second choice. Why are you using dynamic memory there anyway?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int main()
{
    char user;

    Pizza PizzaHut;

    cout << "\nWould you like to order a pizza [y/n]: " << endl;
    cin >> user;

    while (user == 'y')
    {
            if (user == 'y')
            {
               PizzaHut.menu();
               PizzaHut.setSelection();
               PizzaHut.setSizeQuantity();
               PizzaHut.display();
            }

             cout << "\nWould you like to order a pizza [y/n]: " << endl;
             cin >> user;
    }
    return 0;
}
The question asked me to put it. My problem solved when I remove delete pizza but the question asked to delete the object. What should I do?

(ii) Prompt the user whether he would like to order a pizza. If yes, do the
following:
i. Call the functions menu(), setSelection(), setSizeQuantity(),
display()
ii. Delete the object
Move the delete outside of the loop.

1
2
3
4
5
6
7
8
9
int main()
{
    // ..
    while ( user == 'y' )
    {
         // ...
    }
    delete PizzaHut ;
}
If I move delete PizzaHut outside while and put "Would you like to ..." inside line 4 or outside line 4, I still get the same error.
Topic archived. No new replies allowed.