Using cin to input a single letter into a char

You are not inputting or outputting the characters correctly. char letter[2] is an array of 2 characters, not a single character. You want char letter. Further, you are outputting letter[2], which is the third element of an array that only has two values (indexing in C++ starts from 0; the first element is letter[0] and the second is letter[1])! The output will always be garbage. The correct code should be:

char letter;
cout << "Enter a letter: ";
cin >> letter;
cout << letter;
return 0;

Leave a Comment