if else function problems

I cant quite get this to work my output is always isnt beer the best

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
   void IfBeverage (){
            string drink;
            cout << "What do you want to drink?\n" << "beer\n" << "whiskey\n" << "bleach\n"
            << "or boiling water" << endl;
            getline (cin,drink);

            if (drink == "beer" || "Beer"){
                cout << "isnt beer the best" << endl;
            }else if (drink == "whiskey" || "Whiskey"){
                cout << "That will get you going" << endl;
            }else if (drink == "bleach" || "Bleach"){
                cout << "This may kill ya but go for it" << endl;
            }else if (drink == "boiling water" || "Boiling water"){
                cout << "I could have gave you a blanket if you were cold" << endl;
            }else {
                cout << "I hope you die of herpes and rot in hell" << endl;
            }
        }
to use getline function use string header file

#include<string>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void IfBeverage() {

    std::string drink;
    std::cout << "What do you want to drink?\n" << "beer\n" << "whiskey\n" << "bleach\n"
              << "or boiling water\n" ;
    std::getline ( std::cin, drink );

    if ( drink == "beer" || drink == "Beer" )
        std::cout << "isnt beer the best\n" ;

    else if ( drink == "whiskey" || drink == "Whiskey")
        std::cout << "That will get you going\n" ;

    else if ( drink == "bleach" || drink == "Bleach" )
        std::cout << "This may kill ya but go for it\n" ;

    else if ( drink == "boiling water" || drink == "Boiling water")
        std::cout << "I could have gave you a blanket if you were cold\n" ;

    else
        std::cout << "I hope you die of herpes and rot in hell\n" ;
}

or
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void IfBeverage() {

    std::string drink;
    std::cout << "What do you want to drink?\n" << "beer\n" << "whiskey\n" << "bleach\n"
              << "or boiling water\n" ;
    std::getline ( std::cin, drink );

    if( !drink.empty() ) drink.front() = std::tolower( drink.front() ) ; // #include <cctype>

    if ( drink == "beer" ) std::cout << "isnt beer the best\n" ;

    else if ( drink == "whiskey" ) std::cout << "That will get you going\n" ;

    else if ( drink == "bleach" ) std::cout << "This may kill ya but go for it\n" ;

    else if ( drink == "boiling water" ) std::cout << "I could have gave you a blanket if you were cold\n" ;

    else std::cout << "I hope you die of herpes and rot in hell\n" ;
}
Last edited on
Thanks all I need was #include<string>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 void IfBeverage (){
            string drink;
            cout << "What do you want to drink?\n" << "beer\n" << "whiskey\n" << "bleach\n"
            << "or boiling water" << endl;
            getline (cin,drink);

            if (drink == "beer" ||drink == "Beer"){
                cout << "isnt beer the best" << endl;
            }
            else if (drink == "whiskey" || drink == "Whiskey"){
                cout << "That will get you going" << endl;
            }
            else if (drink == "bleach" || drink == "Bleach"){
                cout << "This may kill ya but go for it" << endl;
            }
            else if (drink == "boiling water" || drink == "Boiling water"){
                cout << "I could have gave you a blanket if you were cold" << endl;
            }
            else {
                cout << "I hope you die of herpes and rot in hell" << endl;
            }
        }
Topic archived. No new replies allowed.