Nov 23, 2021 at 6:13pm UTC
Who told you that "case 'A'...'Z':" is valid case syntax?
Last edited on Nov 23, 2021 at 6:16pm UTC
Nov 23, 2021 at 6:15pm UTC
what is the valid one then
Nov 23, 2021 at 6:16pm UTC
I wouldn't use switch/case for this, it's too restrictive.
Try something like this instead
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <iostream>
using namespace std;
int main()
{
char ch;
cout << "enter a character : " ;
cin >> ch;
if ('a' <= ch && ch <= 'z' )
{
cout << "lowercase\n" ;
}
else if ('A' <= ch && ch <= 'Z' )
{
cout << "uppercase\n" ;
}
else if ('0' <= ch && ch <= '9' )
{
cout << "num\n" ;
}
else
{
cout << "error\n" ;
}
}
inb4 something about ASCII vs EBCDIC on some esoteric computer
Last edited on Nov 23, 2021 at 6:18pm UTC
Nov 23, 2021 at 6:21pm UTC
thank you so much it works but I tried my code in another IDE called dev c++ and it worked perfectly.
Nov 23, 2021 at 6:26pm UTC
Okay so, there is a C extension in GCC that allows for ellipses in case statements. Apparently this bleeds over into GCC's C++ implementation as well. Dev-C++ is most likely using a Windows port of GCC called MinGW.
In other words, it's a non-standard extension, which is why it works on some compilers but not others.
Nov 23, 2021 at 6:34pm UTC
Yeah I got you.
thanks for helping