#include <cstdlib> #include <iostream> using namespace std; int main(int argc, c
ID: 3652796 • Letter: #
Question
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
char letter;
int count = 0;
char response;
do
{
cout << "Enter the phone letters: ";
cin >> letter;
cout << "The converted telephone number is : ";
while (count < 8)
{
switch (letter)
{
case 'A' :
case 'B' :
case 'C' :
case 'a' :
case 'b' :
case 'c' :
cout << '2';
break;
case 'D' :
case 'E' :
case 'F' :
case 'd' :
case 'e' :
case 'f' :
cout << '3';
break;
case 'G' :
case 'H' :
case 'I' :
case 'g' :
case 'h' :
case 'i' :
cout << '4';
break;
case 'J' :
case 'K' :
case 'L' :
case 'j' :
case 'k' :
case 'l' :
cout << '5';
break;
case 'M' :
case 'N' :
case 'O' :
case 'm' :
case 'n' :
case 'o' :
cout << '6';
break;
case 'P' :
case 'Q' :
case 'R' :
case 'S' :
case 'p' :
case 'q' :
case 'r' :
case 's' :
cout << '7';
break;
case 'T' :
case 'U' :
case 'V' :
case 't' :
case 'u' :
case 'v' :
cout << '8';
break;
case 'W' :
case 'X' :
case 'Y' :
case 'Z' :
case 'w' :
case 'x' :
case 'y' :
case 'z' :
cout << '9';
break;
default : count--;
break;
}
count++;
if (count == 3)
{
cout << '-';
count++;
}
if (count == 8)
break;
else
cin >> letter;
}
count = 0;
cout << "Do you want to enter another phone number? [y for yes, n for no] : ";
cin >> response;
} while (response != 'n');
system("PAUSE");
return EXIT_SUCCESS;
}
The problem I'm having is that when I typed CALL HOME, after it asked me if I wanted to enter another phone number in which I typed in 'y,' it automatically asks me to enter the phone letters rather than asking me if I wanted to enter another phone number and type either 'y' or 'n'. What I'm I doing wrong? Look at this photo below:
Explanation / Answer
The program is running fine in codeblocks.
Please make sure you didnt press enter. because than null would be compared with 'n' and since it is not equal, the do-while loop would continue
"Patience is the key to debugging".
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.