ALPHABETIC TELEPHONE NUMBER TRANSLATOR Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion: A, B, and C = 2 D, E, and F = 3 G, H, and I = 4 J, K, and L = 5 M, N, and O = 6 P, Q, R, and S = 7 T, U, and V = 8 W, X, Y, and Z = 9 Create an application that lets the user enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663.   **the code below gives me an error, can't find where its wrong.**     string str = textBox1.Text;             const int SIZE = 12;             Boolean valid = true;             string newStr = "";               if (str.Length != SIZE)             {                 valid = false;             }             for (int i = 0; i < str.Length; i++)             {                 if (str[3] != '-' || str[7] != '-')                 {                     valid = false;                     break;                 }                 else if (i != 3 && i != 7 && !char.IsLetter(str[i]))                 {                     valid = false;                     break;                 }                 else                 {                     switch (char.ToUpper(str[i]))                     {                         case 'A':                         case 'B':                         case 'C':                               newStr += '2';                             break;                           case 'D':                         case 'E':                         case 'F':                               newStr += '3';                             break;                           case 'G':                         case 'H':                         case 'I':                               newStr += '4';                             break;                           case 'J':                         case 'K':                         case 'L':                               newStr += '5';                             break;                           case 'M':                         case 'N':                         case 'O':                               newStr += '6';                             break;                           case 'P':                         case 'Q':                         case 'R':                         case 'S':                               newStr += '7';                             break;                           case 'T':                         case 'U':                         case 'V':                               newStr += '8';                             break;                           case 'W':                         case 'X':                         case 'Y':                         case 'Z':                               newStr += '9';                             break;                           default:                             newStr += char.ToUpper(str[i]);                             break;                     }                 }             }                   if (valid == false)                 {                     MessageBox.Show("Invalid input, check format!");                 }                 else                 {                     label2.Text = newStr;                 }             }           }     }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 19PE
icon
Related questions
Question

ALPHABETIC TELEPHONE NUMBER TRANSLATOR

Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion:

A, B, and C = 2

D, E, and F = 3

G, H, and I = 4

J, K, and L = 5

M, N, and O = 6

P, Q, R, and S = 7

T, U, and V = 8

W, X, Y, and Z = 9

Create an application that lets the user enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663.

 

**the code below gives me an error, can't find where its wrong.**

 

 

string str = textBox1.Text;

            const int SIZE = 12;

            Boolean valid = true;

            string newStr = "";

 

            if (str.Length != SIZE)

            {

                valid = false;

            }

            for (int i = 0; i < str.Length; i++)

            {

                if (str[3] != '-' || str[7] != '-')

                {

                    valid = false;

                    break;

                }

                else if (i != 3 && i != 7 && !char.IsLetter(str[i]))

                {

                    valid = false;

                    break;

                }

                else

                {

                    switch (char.ToUpper(str[i]))

                    {

                        case 'A':

                        case 'B':

                        case 'C':

 

                            newStr += '2';

                            break;

 

                        case 'D':

                        case 'E':

                        case 'F':

 

                            newStr += '3';

                            break;

 

                        case 'G':

                        case 'H':

                        case 'I':

 

                            newStr += '4';

                            break;

 

                        case 'J':

                        case 'K':

                        case 'L':

 

                            newStr += '5';

                            break;

 

                        case 'M':

                        case 'N':

                        case 'O':

 

                            newStr += '6';

                            break;

 

                        case 'P':

                        case 'Q':

                        case 'R':

                        case 'S':

 

                            newStr += '7';

                            break;

 

                        case 'T':

                        case 'U':

                        case 'V':

 

                            newStr += '8';

                            break;

 

                        case 'W':

                        case 'X':

                        case 'Y':

                        case 'Z':

 

                            newStr += '9';

                            break;

 

                        default:

                            newStr += char.ToUpper(str[i]);

                            break;

                    }




                }

            }

 

                if (valid == false)

                {

                    MessageBox.Show("Invalid input, check format!");

                }

                else

                {

                    label2.Text = newStr;

                }

            }

 

        }

    }

    



Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning