I have to write a program where I have to detect how many uppercase letters the inputted string contains.
Normally I can do this by making a very large if statement, where each char is compared to 'A' || 'B' || 'C' || 'D' || 'E' || 'F'|| etc.
Is there an easier way to do this? I was thinking if I can compare the char to their respective ASCII code, something like;
if ( c >= 65 && c <= 90)
where it would test the ascii code of A to Z
For my assignment I have to write it as an if-else statement using conditions, can't use string predefined functions.
Is there any way to check it as an if-else condition?
I cannot use predefined string fuctions such as isupper
If you have studied arrays, you could check if the character is present in an array of upper case characters:
const char[] upper_case_chars[] = "ABCDEFGHIJKLMNOPQSTUVWXYZ" ;
Otherwise, settle for: if ( c >= 'A' && c <= 'Z' )