figuring out if letter is uppercase or lowercase

closed account (ENh0ko23)
So i am doing a code in where i enter in initials and from the initials i entered, the code will say if the letter is uppercase or lowercase. I know i would possibly have to use an if/ else statement but i am completely stuck on how i would know in c++ if it was lowercase or uppercase
Try comparing them, for example
1
2
3
4
5
6
char c;
std::cin >> c;
if (c >= 'a' && c = 'z')
//lowercase
else if (c >= 'A' && c <= 'Z')
//uppercase 

Hi Uhyiluh

why don't use ASCII code?

http://www.ascii-code.com

each letter have code for example lower case letters start from 97 until 122, so if letter is in the rage then you know is lower case, if is in range 65-90 they are upper case.
There are also library functions that will help:

1
2
3
4
5
6
7
#include <cctype>
char c;
std::cin >> c;
if (islower(c)) 
//lowercase
else if (isupper(c)) 
//uppercase  


See:
http://www.cplusplus.com/reference/cctype/
Last edited on
Topic archived. No new replies allowed.