I need help inputting true or false to my trivia question

I wrote a program that asks the user to enter true or false to a trivia question. I learned that standard cin just inputs 1 or 0 for true and false.

I want to be able to input the word true or false but I having problems with my boolalpha stuff:

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
bool answer;

cout << "True or False: Richard Nixon was the first U.S. President to be impeached? " << endl;
cin << boolalpha << answer; // this line is wrong

if(answer)
cout << "Sorry. That is incorrect." << endl;

else
cout << "You are correct!" << endl;

getch();
return 0;
}
I got it going now. I discovered that if you use cin.setf(ios::boolalpha) you can get the input stream to accept the words true and false.
You need to change the operators:

cin >> boolalpha >> answer; //Note: >>
I didn't know that one.
If you want to accept something else, like "yes" / "no", and there is no built in way, just use logicals:
if(answer == "yes") //example. often you iterate uppercase/lowercase the input and check vs one upper/lower answer to match caseless.
Topic archived. No new replies allowed.