I am having trouble with my if else statements. I want it to print You win for the right answer, and you lose for anything else. To me, the logic should work. The computer disagrees however. Here is the code:
#include <iostream>
#include <string>
using namespace std;
string myquiz()
{
string youranswer;
cout << "Enter answer: "; //the question I am asking the user
cin >> youranswer; // their answer
getline (cin, youranswer);
return youranswer;
}
int main()
{
if (myquiz() == "yes") // check to see if the answer if correct
cout << "You win! " << endl;
else //having problems here. The compiler prints you lose even if answer is right...
cout << "You lose! " << endl;
return 0;
}
#include <iostream>
#include <string>
usingnamespace std;
string myquiz()
{
string youranswer;
cout << "Enter answer: "; //the question I am asking the user
cin >> youranswer; // their answer
// getline (cin, youranswer); dont need this you already called cin
return youranswer;
}
int main()
{
if (myquiz() == "yes") // check to see if the answer if correct
cout << "You win! " << endl;
else //having problems here. The compiler prints you lose even if answer is right...
cout << "You lose! " << endl;
return 0;
}