0
Can anyone help me out of this?? This is not working for value more than 5
2 ответов
+ 1
#include <iostream>
using namespace std;
int main() {
int age,ageResult;
cout<<"Enter your age:"<<endl;
cin>>age;
if (age<0) ageResult = -1;
else if (age<5) ageResult = 0;
else if (age<12) ageResult = 1;
else if (age<19) ageResult = 2;
else if (age<50) ageResult = 3;
else if (age<60) ageResult = 4;
else if (age<101) ageResult = 5;
else ageResult = -1;
cout<<"Your age belongs to:"<<ageResult<<"group";
return 0;
}
//That should work, you can't use conditions operator like : 0< age < 5 that is incorrect, either use (age > 0 && age < 5) or simple use : age < 5 in your case not all, first it checks if it is smaller than 0 then if it fails it checks if it is smaller than 5 and so on till the else statement
+ 1
Hey thank you