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;
}
}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.