vendredi 6 novembre 2020

I have a problem with switch statement, in a c++ program

Hi i made a program with switch, if i input a character to show me if is vowel or a consonant if is letter to show me if is odd or even if it's number I don't understand where is the problem, in condition is obligatory to use switch. The problem is: It doesn't give me any error but, when i input a letter it also shows me if that letter is even or odd. How can i fix this?

  char n;
  cout<< "Input character : "; cin>>n;
  switch(n){
  case 'A':
  case 'a':
  case 'E':
  case 'e':
  case 'I':
  case 'i':
  case 'O':
  case 'o':
  case 'U':
  case 'u':
  cout<<n<< " vowel ."<<endl; break;
  case 'B':case 'b':case 'C':case 'c':case 'D':case 'd':
  case 'F':case 'f':case 'G':case 'g':case 'H':case 'h':
  case 'J':case 'j':case 'K':case 'k':case 'L':case 'l':
  case 'M':case 'm':case 'N':case 'n':case 'P':case 'p':
  case 'Q':case 'q':case 'R':case 'r':case 'S':case 's':
  case 'T':case 't':case 'V':case 'v':case 'W':case 'w':
  case 'X':case 'x':case 'Y':case 'y':case 'Z':case 'z':
  cout<<n<< " is consonant ."<<endl; break;
  }

  switch(n%2 ==0){
  case 0: cout<<n<< " is even"; break;
  case 1: cout<<n<< " is odd"; break;
  default:cout<<n<< " is simbol"<<endl; break;
  }

Aucun commentaire:

Enregistrer un commentaire