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;                 }             }           }     }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education