Cannot read quantity

Hello guys, I need your help to solve this. I don't know why it skipped at line 48 without letting user to input the quantity. Is there something wrong with my syntax? Thanks in advance.

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

class Pizza
{
private:
    string name;
    int size, 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;
            }

            else
            {
                price = 35.30;
            }
        }

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

            else
            {
                price = 33.30;
            }
        }

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

            else
            {
                price = 36.60;
            }
        }
    }

    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;

        totalprice = quantity * price;
    }
};

int main()
{
    char user;

    Pizza *PizzaHut = new Pizza();

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

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

        delete PizzaHut;
    }
}
cin >> size fails because you inserted a letter and size is an int. That will set the fail flag of cin so that all future read operations on cin will fail (return immediately).
I don't see that it skips line 48. What I see is that you calculate totalprice after it is displayed
Topic archived. No new replies allowed.