+ 1

how do I use multiple if statements and make it so that it only outputs one result? like if I said the age is 100, higher than 21 is adult, higher than 42 is senior, but how do I make it so that it only outputs senior?

17th Jun 2016, 2:25 PM
Heng Gene Sern
Heng Gene Sern - avatar
6 Answers
+ 9
int age; if( age >= 21 && age <= 42 ){ cout << "adult"; }else if( age > 42 ) { cout << "senior"; }else { // output something when the age less than 21 }
17th Jun 2016, 3:59 PM
Hossam Almelyan
Hossam Almelyan - avatar
0
int age; cin>>age; if( age >= 21 && age <= 42 ){ cout << "adult"; } else if( age > 42 ) { cout << "senior"; }else { cout<<" age >=21"; }
18th Jun 2016, 6:52 AM
Vivek Sharma
Vivek Sharma - avatar
0
// DRY if (age > 42) {} else if (age < 21) {} else {}
19th Jun 2016, 9:36 AM
sebas86
0
int age = 0; cout << "enter your age:" ; cin >> age; //lf the user enters a value greater than or //equal to 42 print out senor lf(age >= 42){ cout << "senor" << endl; }
19th Jun 2016, 5:14 PM
Alan
- 1
Why have multiple choices if you only want one result: => 42?
18th Jun 2016, 1:44 AM
ZinC
ZinC - avatar
- 1
int age; cinâ€șâ€șage; if(ageâ€ș=21&& age â€č=41) cout â€čâ€č"adult"; else coutâ€čâ€č"senior";
18th Jun 2016, 10:47 PM
mogdad fadul
mogdad fadul - avatar