1
| bool bValue; |
1
2
| bool bValue1 = true ; // explicit assignment bool bValue2( false ); // implicit assignment |
1
2
| bool bValue1 = ! true ; // bValue1 will have the value false bool bValue2(! false ); // bValue2 will have the value true |
1
2
3
4
5
6
7
| bool bValue = true ; cout << bValue << endl; cout << !bValue << endl; bool bValue2 = false ; cout << bValue2 << endl; cout << !bValue2 << endl; |
1
2
3
4
5
| bool bValue = true ; if (bValue) cout << "bValue was true" << endl; else cout << "bValue was false" << endl; |
1
2
3
4
5
| bool bValue = true ; if (!bValue) cout << "The if statement was true" << endl; else cout << "The if statement was false" << endl; |
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; // returns true if x and y are equal bool IsEqual( int x, int y) { return (x == y); // use equality operator to test if equal } int main() { cout << "Enter a value: " ; int x; cin >> x; cout << "Enter another value: " ; int y; cin >> y; bool bEqual = IsEqual(x, y); if (bEqual) cout << x << " and " << y << " are equal" <<endl; else cout << x << " and " << y << " are not equal" <<endl; return 0; } |
1
2
3
4
| if (IsEqual(x, y)) cout << x << " and " << y << " are equal" <<endl; else cout << x << " and " << y << " are not equal" <<endl; |
0 comments: