-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbool.cpp
More file actions
49 lines (37 loc) · 1.52 KB
/
Copy pathbool.cpp
File metadata and controls
49 lines (37 loc) · 1.52 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <cmath>
using namespace std;
int main () {
//bool data type
//true(1) and false(0)
// bool AreYouAdult = true; //0 and 1 can be used to replace true and false
// bool YouHateCats = false;
// cout << boolalpha; // it will convert 1 into true and 0 into false in terminal
// cout << "Are you adult : " << AreYouAdult << endl ;
// cout << noboolalpha; // it will stop boolalpha and both can be used to gether with sode between them if you want to get true or false value in specific line
// cout << "Do you hate cats : " << YouHateCats << endl ;
// //boolean expression
// cout << boolalpha <<"Is 10 greater than one :" << (10>1) << noboolalpha << endl;
// cout << boolalpha <<"Is 10 equal to 10.001 :" << (10 == 10.001) << noboolalpha << endl;
// cout << boolalpha <<"Is 10 equal to round up of 10.001 :" << (10 == round(10.001)) << noboolalpha << endl;
//Store the Result in a Boolean Variable
int nx = 10 ;
int nv = 20 ;
bool big = nv > nx ;
cout << big << endl;
//real life eg:
int myAge = 19 ;
int adult = 18 ;
cout << boolalpha << (myAge >= adult) << endl ;
//if else with boolean
int age ;
int voter = 18 ;
cout << "enter your age :";
cin >> age ;
int rem = voter - age; //declare after getting age
if (age >= 18){
cout << "You can vote";
}else {
cout << "You can't vote your minimum age must be 18 "<< endl << "You can vote after " << rem <<" year";
}
}