figuring out if letter is uppercase or lowercase

Apr 4, 2017 at 6:01pm
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
Apr 4, 2017 at 6:04pm
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 

Apr 4, 2017 at 6:14pm
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.
Apr 4, 2017 at 6:14pm
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 Apr 4, 2017 at 6:15pm
Topic archived. No new replies allowed.