Question
/*To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can
/*To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies might use more than seven letters. For example, 225-5466 can be displayed as CALL HOME, which uses eight letters. Write a program that prompts the user to enter a telephone number expressed in letters and outputs the corresponding telephone number in digits. If the user enters more than seven letters, then process only the first seven letters. Also output the (hyphen) after the third digit. Allow the user to use both uppercase and lowercase letters as well as spaces between words. Moreover, your program should process as many telephone numbers as the user wants. (You can use While and switch statements, Use a function, called converting_letter_number, for converting letter to number to get a full credit).
p.s (please include comments, and dont use an array)
heres a piece of my code that I tried on my own:
#include
// void converting_letter_number(char phoneNumber); int main() { //Define Variables int counter; char phoneNumber; char
//Prompt User cout << "Enter a phone number in letters ONLY." << endl; cin >> phoneNumber; converting_letter_number(phoneNumber); for (counter = 0; counter > 7; counter++) { cin >> phoneNumber;
if (counter = 3) cout << "-"; converting_letter_number(phoneNumber);
} system("pause"); return 0; }
void converting_letter_number(char phoneNumber) { if (phoneNumber >= 'A' && phoneNumber <= 'Z' || phoneNumber >= 'a' && phoneNumber <= 'z') switch (phoneNumber) { case 'A': case 'a': case 'B': case 'b': case 'C': case 'c': cout << 2; break; case 'D': case 'd': case 'E': case 'e': case 'F': case 'f': cout << 3; break; case 'G': case 'g': case 'H': case 'h': case 'I': case 'i': cout << 4; break; case 'J': case 'j': case 'K': case'k': case 'L': case 'l': cout << 5; break; case 'M': case 'm': case 'N': case 'n': case 'O': case 'o': cout << 6; break; case 'P': case 'p': case 'Q': case 'q': case 'R': case 'r': case 'S': case 's': cout << 7; break; case 'T': case 't': case 'U': case 'u': case 'V': case 'v': cout << 8; break; case 'W': case 'w': case 'X': case 'x': case 'Y': case 'y': case 'Z': case 'z': cout << 9; break; default: cout << "Wrong input" << endl;
} }
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