please help with switch loops

So i am trying to have the user input a letter, then use a switch loop to determine what number on the phone keypad the letter corresponds to. Then i want to print the output of the letter and the digit variables. However the last 2 cout statements do not work and nothing ends up printing in the command prompt except for the statements before the switch loop. If anybody could help explain what it wrong with my code i would be very appreciative.

#include <iostream>

using namespace std;

int main()
{
char letter;
int digit;
cout << "Enter a letter: " << endl;
cin >> letter;
cout << endl;
switch (letter)
{
case 'a':
case 'b':
case 'c':
case 'A':
case 'B':
case 'C':
digit = 2;
break;

case 'd':
case 'e':
case 'f':
case 'D':
case 'E':
case 'F':
digit = 3;
break;

case 'g':
case 'h':
case 'i':
case 'G':
case 'H':
case 'I':
digit = 4;
break;

case 'j':
case 'k':
case 'l':
case 'J':
case 'K':
case 'L':
digit = 5;
break;

case 'm':
case 'n':
case 'o':
case 'M':
case 'N':
case 'O':
digit = 6;
break;

case 'p':
case 'q':
case 'r':
case 's':
case 'P':
case 'Q':
case 'R':
case 'S':
digit = 7;
break;

case 't':
case 'u':
case 'v':
case 'T':
case 'U':
case 'V':
digit = 8;
break;

case 'w':
case 'x':
case 'y':
case 'z':
case 'W':
case 'X':
case 'Y':
case 'Z':
digit = 9;
break;
}
cout << "Letter: " + letter << endl;
cout << "Digit: " + digit << endl;
return 0;
}
Last edited on
<< instead of +

1
2
cout << "Letter: " << letter << endl;
cout << "Digit: " << digit << endl;
@wildblue hahaha shit idk how i fucked that one up thank you
Topic archived. No new replies allowed.