Question
The program Telephone Digits outputs only telephone digits that correspond to uppercase letters. Rewrite the program so that it processes both uppercase and lowercase letters
The program Telephone Digits outputs only telephone digits that correspond to uppercase letters. Rewrite the program so that it processes both uppercase and lowercase letters and outputs the corresponding telephone digit. If the input is something other than an uppercase or lowercase letter, the program must output an appropriate error message (The error message should contain the phrase Invalid input). This the code: //********************************************************** // Program: Telephone Digits // This is an example of a sentinel-controlled loop. This // program converts uppercase letters to their corresponding // telephone digits. //********************************************************** #include using namespace std; int main() { char letter; int digit, num; cout << "Program to convert uppercase letters to " << "their corresponding telephone digits." << endl; cout << "To stop the program enter #." << endl; cout << "Enter an uppercase letter: "; cin >> letter; cout << endl; while (letter != '#') { cout << "Letter: " << letter; cout << ", Corresponding telephone digit: "; num = static_cast(letter) - static_cast('A'); if (0 <= num && num < 26) { digit = (num / 3) + 2; if (((num / 3 == 6 ) || (num / 3 == 7)) && (num % 3 == 0)) digit = digit - 1; if (digit > 9) digit = 9; cout << digit << endl; } else cout << "Invalid input." << endl; cout << " Enter another uppercase " << "letter to find its corresponding " << "telephone digit." << endl; cout << "To stop the program enter #." << endl; cout << "Enter a letter: "; cin >> letter; cout << endl; } //end while return 0; } I tried to type it in but it keep saying error. Please Help
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started