I am trying to use nested ternary operators using following code, but it is giving wrong answer, I am not getting what's the mistake is.
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World\n";
int age, Result ;
cout<<"Enter age:";
cin>>age;
Result=age<0?-1
:0<=age<=10?0
:11<=age<=18?1
:-2;
cout<<"Result is: "<<Result;
return 0;
}
For the input age 13 its giving Result as 0 and for input age 20 also its giving result as 0. I am not getting what's the mistake. Could you help me? Thank you.