This is currently an unfinished version of a code i'm working on right now. I am wondering why my code shows me digits after i run my code. How do i make it so that when i run my code, it gives me the correct output instead of giving my some random numbers?
For instance, when i type in q, it gives me that q is a lowercase but, it gives me 81 as the output for the uppercase. I don't understand why it does that.
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
cout << "Input a character:";
char ch;
cin >> ch;
if (islower(ch))
cout << ch << " is a lowercase letter and " << toupper(ch) << " is the uppercase of the character." << endl;
if (isdigit(ch))
cout << ch << " is a digit." << endl;
else
cout << ch << " is not a digit." << endl;
system("pause");
return 0;
}
It's all about how the << operator interprets types. When it sees toupper(ch) by itself, it sees an int, because that's the return type of toupper(ch). The behavior for int is to print a number. Putting (char) in the front tells it to take the result of toupper(ch) and interpret the number as a character. The behavior of << in regards to char is to print the letter instead of the ASCII code.