bool true/false print out

So im reading a book on C++ and it asked me to input this code.

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
#include <iostream>


using namespace std;

int main()
{
	cout.setf(ios base::boolalpha);

	float num1 = 0.0f;
	float num2 = 0.0f;

	cout << "Enter a number: ";
	cin >> num1;

	cout << "Enter another number: ";
	cin >> num2;

	bool isEqual = num1 == num2;
	bool isNotEqual = num1 != num2;

	cout << "isEqual        = " << isEqual << endl;
	cout << "isNotEqual     = " << isNotEqual << endl;

	cin.get();
	return 0;
}


However for IOS it says type name not allowed and for base it says expected a ')'. While I know what both of these mean i dont know how to get around them. Any ideas? As well i would like to mention that my goal is for it to print out true or false rather than 1 or 0. Thanks in advance.
Use the std::boolalpha manipulator from the iomanip library

I see your problem, line 8 should be
cout.setf(std::ios_base::boolalpha);
Last edited on
That got it. Thanks a bunch!
You can also do std::cout << std::boolalpha; or std::cout.boolalpha(); I think (not positive on the second but first works).
Registered users can post here. Sign in or register to post.