This is a small portion of a program I am making. When the correct answer is entered, it still says incorrect. It is probably really simple, but I cant find my error.
int main()
{
string penguin;
string answer;
int numGuesses;
for (numGuesses = 4; numGuesses > 0; numGuesses--)
{
cout << "I like to swim." << endl;
cin >> answer;
if (answer == penguin)
cout << "That is correct!" << endl;
else
numGuesses--;
cout << "Incorrect. You have " << numGuesses << " guesses left." << endl;
cout << "I like to eat fish." << endl;
cin >> answer;
if (answer == penguin)
cout << "That is correct!" << endl;
else
numGuesses--;
cout << "Incorrect. You have " << numGuesses << " guesses left." << endl;
cout << "I am mostly black and white." << endl;
cin >> answer;
if (answer == penguin)
cout << "That is correct!" << endl;
else
numGuesses--;
cout << "Incorrect. You have " << numGuesses << " guesses left." << endl;
cout << "I usually live where it is very cold." << endl;
cin >> answer;
if (answer == penguin)
cout << "That is correct!" << endl;
else
numGuesses--;
cout << "Incorrect. You have " << numGuesses << " guesses left." << endl;
cout << "I am a penguin." << endl;
You need to enclose your if...else statements with { } if there is more than one statement following an if or else or else if. Without { } only the first statement following the if, else, etc... will be executed if the condition is true. Everything else will always be output.