Char

Why does it output a number instead of a letter

[]
#include <iostream>
#include <string>

using namespace std;

int main()
{
char theChar;
cout << " Enter a Char," << endl;
cin >> theChar;
cout << "theChar " << theChar + 1 << endl;
return 0;
}
[/code]
Because you're adding a char and an int the compiler implicitly converts the char to an int for the addition then prints that int. If you do the addition prior to the print statement it should then print the character.
Last edited on
1 - Do not use
#include<string>
, you're not using it anywhere.
2 - Use theChar = theChar + 1 || OR || theChar++ in a separate statement.
3 - Improve your formatting.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

int main()
{
char theChar;

cout << " Enter a Char:" << endl;
cin >> theChar;	

theChar++;

cout << "theChar " << theChar << endl;

system("pause");
return 0;
}
Topic archived. No new replies allowed.