# Uppercase and lowercase

• 03-09-2005
StarOrbs
Uppercase and lowercase
Okay a part of the program I have to write has to switch "one" lowercase letter and make it uppercase and vice versa. I can't use strings or anything more advanced then a begginers c++. I don't know why, he likes to be a real pain sometimes. The only thing I can think of is 54 if statements.
I've also been told I can do it via ASCII values but I can't seem to figure that out. unless somehow you store the ascii value of every letter but that would be the same amount of work. Any ideas anyone?

if (letter == 'A')
letter = 'a'
if (letter == 'a')
letter = 'A'
Etc..
• 03-09-2005
InvariantLoop
you could use something like this
Code:

```int main() {             char str[10];         int i, delt ='a' -'A';               while (str[i]){                 if ((str[i] >='a') && (str[i] <='z'))                 str[i] -=delt; /*convert to upper case*/                 i++;                       } }```
Thats much of your program but it will not work as it is, you have to figure out the rest.
• 03-09-2005
Scribbler
Quote:

Originally Posted by StarOrbs
I don't know why, he likes to be a real pain sometimes.

Probably because he's providing you a learning experience in logic/design.

Study the ascii chart a bit and you'll find a pattern. Pay particular attention to the binary values of letters chars A-Z and compare them to chars a-z. When you note the difference, determine what simple operation will change lower to upper and upper to lower regardless of its value.
• 03-09-2005
hk_mp5kpdw
Can you use the islower/isupper/tolower/toupper functions?
• 03-09-2005
Lithorien
Why not cast to an int (int)variable, check the int value, if it's between X and Y (where X is lowercase a and Y is lowercase z) than do toupper(), and if it's between Z and Q (where Z is uppercase a and Q is uppercase z) than do tolower()?