Answered step by step
Verified Expert Solution
Question
1 Approved Answer
To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 4 3
To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number can be shown as GET LOAN.
In some cases, to make a telephone number meaningful, companies might use more than seven letters. For example, can be displayed as CALL HOME, which uses eight letters.
Instructions
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.
Use the dialpad below for reference: phoneDialpad.jpg
The program should accept input and produce output similar to the example program execution below.
Enter Yy to convert a telephone number from
letters to digits.
Enter any other letter to terminate the program.
Y
Enter a telephone number using letters: Hello world
The corresponding telephone number is:
To process another telephone number, enter Yy
Enter any other letter to terminate the program.
z
Task #: Correct output for single entry
Task #: Correct output for multiple numbers
I get past the first task but the second task keeps failing on me and I am stumped as to why. here is my current code if it helps you. please help me figure this out!
#include
#include
#include
#include
using namespace std;
Function to convert a character to its corresponding phone digit
char letterToDigitchar letter
letter toupperletter; Convert to uppercase for uniformity
if letter A && letter C return ;
if letter D && letter F return ;
if letter G && letter I return ;
if letter J && letter L return ;
if letter M && letter O return ;
if letter P && letter S return ;
if letter T && letter V return ;
if letter W && letter Z return ;
return ; Default case for nonletter characters eg spaces
int main
char continueConversion;
do
cout "Enter Yy to convert a telephone number from letters to digits.
;
cout "Enter any other letter to terminate the program.
;
cin continueConversion;
cin.ignore; Clear the newline character from the input buffer
if continueConversion Y continueConversion y
string input, numericPhoneNumber;
cout "Enter a telephone number using letters: ;
getlinecin input;
int count ;
for char c : input
if isalphac && count
numericPhoneNumber letterToDigitc;
count;
Insert hyphen after the third digit if length is at least
if numericPhoneNumberlength
numericPhoneNumber.insert;
cout
The corresponding telephone number is:
;
cout numericPhoneNumber endl;
cout To process another telephone number, enter Yy
;
cout "Enter any other letter to terminate the program.
;
cin continueConversion;
cin.ignore; Clear the newline character from the input buffer
while continueConversion Y continueConversion y;
return ;
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