toupper()

Have a choice to input 3 letters S or P or Q. I need to convert them to upper if user inputs lower cased letters.
Hi,

toupper() is the command you need.

you will need to #include <ctype.h>

and do something like follows

1
2
3
4
5

    char    upper;

    upper = toupper(temp);
1
2
3
4
5
6
7
8
9
   //First input
   cout << setw(63) << "S for squareroot P for Power Q to Quit: ";
   cin  >> LETTER;
   cout << "\n";
   
   UPPER = toupper( 's' );
  
   //If the input isnt Quit
   while (LETTER != 'Q')


what am i doing wrong? it doesnt work
Last edited on
you can make 6 separate char .
char a ='s'
char b ='S'
char c = 'q'
and so on...
then char a == char b, char c == char d,...
this is one possible ways.
or you can do this
try replacing line 9 with while toupper((LETTER != 'q'))
Last edited on
hi nickx522,

assume you read a letter like this:
1
2
char letter;
cin >> letter;

then you have got many possibilities:

1. just check for lower and upper case like:
( "&&" this means and .. so "as long as the letter is not q and not Q")
1
2
3
4
5
6
7
char letter;
cin >> letter;

while( letter != 'q' && letter != 'Q' ) {

//your code
}

2. you convert the input letter to an upper case
1
2
3
4
5
6
7
8
char letter;
cin >> letter;

//at this moment letter is lower or upper case
letter = toupper(letter);
//now it is upper case

while(letter != 'Q')


lg,
flowly
store the input

char letter;
cin >> letter;

then subtract 32 from the char to change its ascii code.

letter ascii
a = 97
A = 65
@leecheneler:
If you do it that way then you have to make sure the letter isn't already uppercase. Otherwise 'A' would be converted to '!'.
Last edited on
Yes sorry, i forgot to mention the fail safes.
Topic archived. No new replies allowed.