Victor Bazarov <v.********@comAcast.net> wrote in message news:<Bm****************@newsread1.dllstx09.us.to. verio.net>...
D wrote: Can I use a sentinel with a while loop and a nested if statement in a
program?
For example I ask the user for a letter of the alphabet and the output
returns a number(non-ascii). Then the program continues to loop until
the sentinel character is used. Thanks
Sure you can.
Then my coding is off.
cout <<"This program is designed to convert an upper case letter of
the alphabet ";
cout << "and convert it into a number that corresponds to a number on
a standard ";
cout << "telephone dial.\n";
cout <<"When you are finished please enter a '?' to stop the
program.\n";
cout <<"Enter your character " << counter << ":";
cin >> ch;
while (ch != '?')
{
if (ch >= 'A' && ch <= 'C')
num = 2;
else if (ch >= 'D' && ch <= 'F')
num = 3;
..
..
..I purposely omitted the rest of the code for the sake of saving space
..
..
cout <<"The number for that character is " << num << endl;
cout << "Enter your character " << ++counter << ":"<< endl;
cin >>ch;
My variables are:
char ch;
int num, counter = 1;
Now the loop iterates only once then quits even though the sentinel is
not entered. I was reading in one book that I can reference the
sentinel again in an if statement but that would be redundant. Any
suggestions on were I'm coding wrong? Thanks.
D