Boolean

Does anyone have some ideas on how to write a functionality to interpret "y" and "n" as true and false assignments using the boolean statement? I am really confused with the boolean statement.
functionality like you want to make a function which compares 2 bool variables?
Well what I want to do is ask the user to enter names of past and present employees. Then I want to ask the user if he wants to see only the active employees only. If the user types "y", I want it to check and display each of the elements that is assigned true with. If the user says "n", then I want it to display all of them.
Last edited on
1
2
3
4
5
6
7
8
9
10
char input;
std::cin >> input;

if (input == 'y') {
    // etc. etc. etc.
} else if (input == 'n') {
    // etc. etc. etc.
} else {
    std::cerr << "That wasn't a valid input!\n";
}

You can also just store it in a boolean variable, like so:
1
2
3
4
5
6
char input;
std::cin >> input;

bool val = (input == 'y'); // true if 'y', false otherwise
// OR
bool val = (input != 'n'); // false if 'n', true otherwise 
@NT3 That really helped me a lot, thank you so much!
Topic archived. No new replies allowed.