Exercise 3-11 (Boolean with double values)
Chapter_3 Exercise_3-10 Boolean | Bitwise Exercise_3-12 |
Exercise 3-11 TCP1, p. 228
Exercise 3-11. Modify Boolean.cpp (previous program) so that it works with double values instead of ints.
BoolDouble.cpp download
// Relational and logical operators
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
double i,j;
cout << "Enter a number: ";
cin >> i;
cout << "Enter another number: ";
cin >> j;
cout << "i > j is " << (i > j) << endl;
cout << "i < j is " << (i < j) << endl;
cout << "i >= j is " << (i >= j) << endl;
cout << "i <= j is " << (i <= j) << endl;
cout << "i == j is " << (i == j) << endl;
cout << "i != j is " << (i != j) << endl;
cout << "i && j is " << (i && j) << endl;
cout << "i || j is " << (i || j) << endl;
cout << "(i < 10) && (j < 10) is " << ((i < 10) && (j < 10)) << endl;
}
/*
g++ BoolDouble.cpp -o BoolDouble
./BoolDouble
Enter a number: 0
Enter another number: 0
i > j is 0 // false
i < j is 0
i >= j is 1 // true
i <= j is 1
i == j is 1
i != j is 0
i && j is 0
i || j is 0
(i < 10) && (j < 10) is 1
./BoolDouble
Enter a number: 0.1
Enter another number: 0.01
i > j is 1
i < j is 0
i >= j is 1
i <= j is 0
i == j is 0
i != j is 1
i && j is 1
i || j is 1
(i < 10) && (j < 10) is 1
./BoolDouble
Enter a number: 1
Enter another number: 1.01
i > j is 0
i < j is 1
i >= j is 0
i <= j is 1
i == j is 0
i != j is 1
i && j is 1
i || j is 1
(i < 10) && (j < 10) is 1
./BoolDouble
Enter a number: 9.999
Enter another number: 9.99
i > j is 1
i < j is 0
i >= j is 1
i <= j is 0
i == j is 0
i != j is 1
i && j is 1
i || j is 1
(i < 10) && (j < 10) is 1
./BoolDouble
Enter a number: 10
Enter another number: 9.999999
i > j is 1
i < j is 0
i >= j is 1
i <= j is 0
i == j is 0
i != j is 1
i && j is 1
i || j is 1
(i < 10) && (j < 10) is 0
*/
Chapter_3 Exercise_3-10 Boolean | BACK_TO_TOP | Bitwise Exercise_3-12 |
Comments
Post a Comment