-2

I'm learning C++ right now, but I can't seem to find out how to make an input be accepted whether or not there are any capitals anywhere. For example, if someone input "sAndwiCh" in a case in a switch statement desiring "sandwich," how could I perform the following action by making the program allow the input to be any case of every letter? Thank you.

2

1 Answer 1

0

Use the toupper() and/or the tolower() functions of the ctype.h header file. So, to make your comparisons:

char input[3] = {'A', 'b', 'C'}; unsigned int index = 0U; unsigned int outputVal = 0U; while(index < 3) { switch(tolower(input[index])) { case 'a': outputVal += 1; break; case 'b': outputVal += 2; break; case 'c': outputVal += 3; break; } ++index; } 

At the end of this, outputVal should have a value of 6.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.