Question
This is for C Programming: Complete the program by providing the additional if-else branches for decoding other letters in a phone number. Try incrementally writing
This is for C Programming:
Complete the program by providing the additional if-else branches for decoding other letters in a phone number. Try incrementally writing the program by adding one "else if" branch at a time, testing that each added branch works as intended.
#include
int main(void) { char phoneChar; // Current char in phone number string
printf("Enter phone number: ");
scanf("%c", &phoneChar); // Reads first char of user input printf("Numbers only: ");
while (phoneChar != ' ') {
if (((phoneChar >= '0') && (phoneChar <= '9')) || (phoneChar == '-')) { printf("%c", phoneChar); // Print element as is } else if ( ((phoneChar >= 'a') && (phoneChar <= 'c')) || ((phoneChar >= 'A') && (phoneChar <= 'C')) ) { printf("2"); } // FIXME: Add remaining else-if branches else { printf("?"); }
scanf("%c", &phoneChar); // Read next char of user input }
printf(" ");
return 0;
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