0

i need help with this very simple question....
the default in this program will just display the wrong input
if the input entered by user is different with the data type of the variable which is char..
but not if the user entered the the word which is the character is located in front of the word...

in my program, if the user entered apple instead of 'a',this program will still print that i'm in the red team...

I want this program to display the input error..

this is my code :

#include <iostream>
using namespace std;

int main () {

char answer;

cout<<"Enter Your Team :";
cin>>answer;

switch (answer) {
    case 'a' :
     cout<<"You in the Red Team";
     break;

    case 'b' :
     cout<<"You in the blue team";
     break;

    default :
     cout<<"wrong input";
     break;
}
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by firstPerson
0

Then you should take the input as a string. Then if the size of the string is
greater than 1 then display an error message, else compare it with a or b.
Doing this way you would have to use if/else. This isn't that bad if you
don't have many cases.

This topic has been dead for over six months. 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.