Hi, I have run into an error on an exercise and I can't figure out why.
The goal of the program is to intake characters(letters only) and repeat them with the opposite capitalization, the problem I am running into is that it repeats the characters but in the same capitalization.
Could anyone shed some light on what I am doing incorrectly? (p.s. very jet lagged at the moment, i may fall asleep soon so my reply may be delayed.)
The reason it shows the same case is you call the function. But functions do not change the value without you telling it to.
Try this (I am assuming your toupper and tolower function return a char value) cout << toupper (ch)
and cout << tolower (ch)
Note: This does not change the value but merely displays it
Hope this helps :)
by special characters do you mean iscntrl & ispunct functions?
I meant any character that's not a digit or part of the alphabet. So, in your previous code, characters such as '*', '$', '~', '+', '/' etc. would go into your else case.
If so could I just not add to line 13 with the || ?
With your switch as above, any character entered that's not a lower case c, t, p, or g would go into the default case, so non-digit, non-alphabet characters are already inherently taken care of.
When I run the code the first character I entered is not accepted as a possible choice even if it is a valid one, can anyone shed some light?
The user's first choice is going into cin.get(ch);, then their next choice is going into cin >> ch. You should remove cin.get(ch);