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; } } } }
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
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;
}
}
}
}
Step by step
Solved in 3 steps with 2 images