dimanche 28 juin 2015

"If" statement does not execute properly c++

I am having a small issue regarding the if statement in c++. Here is a snippet of the code:

string answer;
cin >> answer;

if (answer == "stay in bed")
    {
        cout << "You lay there, motionless. Silent.";
    }
else if (answer == "go to the bathroom")
    {
        cout << "You get up and walk across the hall to the bathroom.";
    }
else if (answer == "go downstairs")
    {
        cout << "You get up and walk down the stairs to the kitchen.";
    }
else
    {
        cout << "That is not a valid answer...";
    }

When I input any value, I get the output from the else statement. As in, "That is not a valid answer..."

Any advice? Also I'm doing all this in Code::Blocks.

Aucun commentaire:

Enregistrer un commentaire