Converting user imputed 'A' to 'a'

I am trying to let the user input a character (a-z). If they put in a capital letter (A-Z), I want it to convert it to a lowercase. What am I doing wrong?

1
2
3
4
5
6
char p1choice;

cout << "Choose the square you want: ";
cin >> p1choice;

tolower(p1choice);
Last edited on
The computer does not differentiate between data types. It sees a number. The data type is determined on how the code processes the number...
Check out http://www.asciitable.com/ and you'll see that capital and lower case all have a difference of 32. So you can build a simple converter by checking if the value is between 65 and 90. If so, add 32. You now have capital letters.
if(atoi(plchoice) > 90)
      plchoice += 32;

this might be useful to you..
Last edited on
closed account (zb0S216C)
tolower() doesn't modify the variable you give it. Instead, it returns the modified character:

 
p1choice = tolower(p1choice);

Wazzak
Last edited on
Topic archived. No new replies allowed.