Setting true or false by user

So im trying to do something, ask questions and then find out a character, if i have a bool, lets name it isMale, as a variable for the question if a character is male or not, how do i let the user put it to true or false?

i know its basic stuff but im really new sorry

Ask the question, "Are you male? (1 for true, 0 for false): "

Retrieve the console input into a Boolean type variable; 0 is false, any non-zero value is true.

Easy peasy.

See if you can write some code now and post it here, show us what you know.

And when posting code:

PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either
If you want the user to type "true" or "false" you can use the I/O manipulator std::boolalpha as follows
1
2
3
4
5
6
7
8
9
10
11
12
#include <iomanip>
#include <iostream>

int main()
{
  bool is_male = false;

  if (! (std::cin >> std::boolalpha >> is_male))
    return 1; 
  
  std::cout << "User is male: " << std::boolalpha << is_male << '\n';
}
Topic archived. No new replies allowed.