0

Good Afternoon,

I want to convert this if-else statement to a switch statement.
The if-statement is:

int x;
cout<<"GIve me an int and I tell you whether is even of odd ";
cin>>x;
if (x%2==0)
cout<<x<<" is even."<<endl;
else
cout<<x<<" is odd."<<endl;
2
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by poloblue
0

Where I 'm having problems is dealing with x%2==0.
So far I have this:

int x;
     cout<<"Give me an int and I tell you whether is even of odd ";
     cin>>x;

     switch (x)
     {       
        case 'A':
            x = %2;
            cout<<x<<" is even."<<endl;
        break;
        default:
             cout<<x<<" is odd."<<endl;
     }
0

Ancient Dragon,

I try your advise, but the program execute the default case with every number

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.