ok, i am doing a program where it converts char to upper or lower. I think i have it coded right but when i enter it it outputs a number. What is wrong with my code?
//This is program #1 it calls to switch around the capitalization from lower case to upper case and vice versa
#include <iostream>
#include <fstream>
#include <cctype>
usingnamespace std;
int main()
{
char inputs; //hold 10000 charactors in one simple array for this project to work.
cout << "enter a word: ";
cin >> inputs;
if (isupper(inputs)){
cout << toupper(inputs);}
elseif (islower(inputs)){
cout << tolower(inputs);}
}
output
1 2 3
john@john-K53E:~/Programming/C++/Book Programming Exercises/Chapter 6 Branching Statements And Logical Operators$ ./atout
enter a word: y
121john@john-K53E:
It's because a character is an int, it has a set numerical value. To display a character, you have two options:
1) Leave your code how it is and just cast the output to a char: cout << static_cast<char>(toupper(inputs));
2) Set inputs equal to the return value of the function and then display inputs. This does modify the value of inputs: