In my assignment, I am required to ask the user a question where they respond (y/n) yes or no. I need to convert 'y' to (boolean) true and ''n' to (boolean) false but i am not sure how to do this. Any help would be appreciated.
From what I know about C, true and false are not defined values, and I don't know if there is the variable type bool
(but I'm talking about C, not C++)
I know I'm a newbie when it comes to c++ programming and probably shouldn't give out my codes as they may be faulty, but maybe something like this should help you:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
int main()
{
char c;
bool bb;
do {
cout << "blabla (y/n) ";
cin >> c;
} while (!strchr("yn", tolower(c)));
tolower(c)=='y'?bb=true:bb=false;
cout << (bb?"true":"false");
}