int main()
{
int answer;
int answer2;
cout<<"Do you want to answer a yes or no question ? ";
cin>>answer;
if (answer == "yes")
{
cout<<"Great\n";
cout<<"Now, the question is: have you ever lied ? ";
cin>>answer2;
if (answer2 == "yes")
{
cout<<"Thank you for your honesty.";
}
if else(answer2 == "no")
{
cout<<"That is a lie sir ! ";
}
}
if else(answer == "no")
{
cout<<"You just answered a yes or no question !";
}
return 0;
}
Line 11,16,20,25: You can't compare an int to a string.
Line 20,25: ifelse is not valid. Did you mean elseif ?
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
// int variables can only hold numbers. If you want variables to hold "yes" or "no", use a string.
string answer;
string answer2;
cout<<"Do you want to answer a yes or no question? ";
cin>>answer;
if (answer == "yes")
{
cout<<"Great\n\n"; // Added an extra line to make it look better
cout<<"Now, the question is: have you ever lied? ";
cin>>answer2;
if (answer2 == "yes")
{
cout<<"Thank you for your honesty.";
}
elseif (answer2 == "no") // Use else if instead of if else
{
cout<<"That is a lie sir!";
}
else // Add this line just in case someone inputs something other than "yes" or "no"
{
cout<<"Could not understand input.";
}
}
elseif (answer == "no")
{
cout<<"\nYou just answered a yes or no question!"; // Added an extra line to make it look better
}
else // Add this line just in case someone inputs something other than "yes" or "no"
{
cout<<"Could not understand input.";
}
cout << endl; // Added an extra line to make it look better
return 0;
}