Answer to Question #249744 in C++ for Toby

Question #249744
Rewrite the program of Example 5, Telephone Digits. Replace the statements from Lines 29
to 83 so that the program uses only a switch structure to find the digit that corresponds to an
uppercase letter.
1
Expert's answer
2021-10-12T00:36:57-0400
#include <iostream> 
using namespace std;
int main()
{
    char L;
    cout << "Press # to stop the program from running" << endl;
    cout << "Input a letter: " ;
    cin >> L;
    
    while (L != '#' && L >= 'A' && L <= 'Z') {
        cout << "Letter entered is: " << L << endl;
        cout << "The corresponding telephone digit is: ";
            switch (L) {
                case 'A':
                case 'B':
                case 'C':
                    cout << "2" << endl;
                    break;
                case 'D':
                case 'E':
                case 'F':
                    cout << "3" << endl;
                    break;
                case 'G':
                case 'H':
                case 'I':
                    cout << "4" << endl;
                    break;
                case 'J':
                case 'K':
                case 'L':
                    cout << "5" << endl;
                    break;
                case 'M':
                case 'N':
                case 'O':
                    cout << "6" << endl;
                    break;
                case 'P':
                case 'Q':
                case 'R':
                case 'S':    
                    cout << "7" << endl;
                    break;
                case 'T':
                case 'U':
                case 'V':
                    cout << "8" << endl;
                    break;
                case 'W':
                case 'X':
                case 'Y':
                case 'Z':
                    cout << "9" << endl;
                    break;
                default:
                    break;
            }
            
            cout << "Input another letter to find out the number: ";
            cin >> L;
        }
        return 0;
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS