2 different input values question

float dessert;
cout << "Pick a dessert"
cin >> dessert;

if the user knows that they can only choose ice cream, or pudding,
how can i write it so dessert either equals to ice cream or pudding
this is an if statement btw
Last edited on
closed account (28poGNh0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# include <iostream>
using namespace std;

int main()
{
    cout << "Menu :" << endl;
    cout << "1 : Ice cream" << endl;
    cout << "2 : Pudding" << endl;
     
    int dessert;
    cout << "Pick a dessert"
    cin >> dessert;
    
    if(dessert==1)
        cout << "Take your ice cream" << endl;
    else if(dessert==2) 
        cout << "Take your pudding" << endl;
    else cout << "Get out of my face" << endl;
    
    return 0;
}


Good look
what if instead of number , you do letters instead? does that work as well ex. pudding=z
Last edited on
closed account (28poGNh0)
You asked the user to enter the dessert wich is an interger variable

what about now

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# include <iostream>
# include <string>
using namespace std;

int main()
{
    cout << "Menu :" << endl;
    cout << "Ice cream" << endl;
    cout << "Pudding" << endl;

    string dessert;
    cout << "Pick a dessert -> ";
    getline(cin,dessert);

    if(dessert=="ice cream")
        cout << "Take your ice cream" << endl;
    else if(dessert=="pudding")
        cout << "Take your pudding" << endl;
    else cout << "I said get out of my face" << endl;

    return 0;
}
^but youre suppose to ask the user to input what they want
nvm i solved it, i didnt include char as a variable
Topic archived. No new replies allowed.