+ 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?
6 Respuestas
+ 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
}
0
int age;
cin>>age;
if( age >= 21 && age <= 42 ){
cout << "adult";
}
else if( age > 42 )
{
cout << "senior";
}else
{
cout<<" age >=21";
}
0
// DRY
if (age > 42)
{}
else if (age < 21)
{}
else
{}
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;
}
- 1
Why have multiple choices if you only want one result: => 42?
- 1
int age;
cin››age;
if(age›=21&& age ‹=41)
cout ‹‹"adult";
else
cout‹‹"senior";