cin boolean

Write your question here.
i need to accept true or false as input and split accordingly. i think im missing a concept.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  Put the code you need help with here.
case 3:
		cout << "Enter 1 to convert from decimal to hexadecimal\n" <<
			"Enter 2 to convert from hexadecimal to decimal\n" << endl;
		cin >> z;
		switch (z)
		{
		case 1 :
			cout << "Lower or upper case for hex print out?\n" <<
				"enter 'true' for upper or 'false' for lower" << endl;
			cin >> boolalpha >> t;
			switch (t)
			{
			case true:
				cout << "true" << endl;
				break;
			case false:
				cout << "false" << endl;
				break;
			}
		case 2 :
			cout << " you picked 2" << endl;
			break;
		}
		if i input true it sends me to true and case 2...any other input sends me to case false AND case 2

appreciate any tips
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
string userInput;
cout << "Lower or upper case for hex print out?\n" <<
				"enter 'true' for upper or 'false' for lower" << endl;
cin >> userInput;
bool userInputAsBool;
if (userInput == "true")
{
  userInputAsBool = true;
}
else if (userInput == "false")
{
  userInputAsBool = false;
}
else
{
  // do some error handling
}


ty
Topic archived. No new replies allowed.