Loop

When I debug, for instance a t input, it keeps outputting the corresponding number is 8 over an over until I exit it. Need help finding my mistake.
" "
" "
" "




#include <iostream>
using namespace std;
int main()
{

char letter;


cout << "Enter a letter: ";
cin >> letter;

while (letter != '#')
{

cout << "The corresponding number is ";



switch (letter)
{

case 'A':
case 'a':
case 'B':
case 'b':
case 'C':
case 'c':
cout << "2" << endl;
break;

case 'D':
case 'd':
case 'E':
case 'e':
case 'F':
case 'f':
cout << "3" << endl;
break;

case 'G':
case 'g':
case 'H':
case 'h':
case 'I':
case 'i':
cout << "4" << endl;
break;

case 'J':
case 'j':
case 'K':
case 'k':
case 'L':
case 'l':
cout << "5" << endl;
break;

case 'M':
case 'm':
case 'N':
case 'n':
case 'O':
case 'o':
cout << "6" << endl;
break;

case 'P':
case 'p':
case 'Q':
case 'q':
case 'R':
case 'r':
case 'S':
case 's':
cout << "7" << endl;
break;

case 'T':
case 't':
case 'U':
case 'u':
case 'V':
case 'v':
cout << "8" << endl;
break;

case 'W':
case 'w':
case 'X':
case 'x':
case 'Y':
case 'y':
case 'Z':
case 'z':
cout << "9" << endl;
break;


default: cout << "Invalid input.";

}
}

system("pause");
return 0;




}
Hi!

while (letter != '#')

letter is never in a situation where it's not '#' :)
I'm confused by what you mean...sorry I'm completely new to programming. I just started last week so bear with me.. haha
No problemo, here's a real world example:

"Hey Aman03"

"yeah?"

"As long as you're not a mushroom, please go ahead and hop on one leg"

"oh okay"

**Aman03 hops on one leg for eternity**

basically you ask the user for a character one time and then after you ask for the character you loop for eternity because that character isn't '#'
Ok I understand that much now. So it seems like that line I have needs to be altered in some way, but if I get rid of the "!= '#'" it gives no output at all. Is there something else that should be in the # position?
That's up to you :)

Now that you know the problem, you have the brain power to come up with a solution!
1
2
cout << "Enter a letter: ";
cin >> letter;



you may put these two inside the loop, so the it will still ask for a letter to input everytime it loops, and then there will be now a possibility that the loop will stop
Topic archived. No new replies allowed.