People sometimes give their telephone number using one or more alphabetic charac
ID: 3542926 • Letter: P
Question
People sometimes give their telephone number using one or more alphabetic characters.
Write a program that takes a single letter and displays the corresponding number. Look
at your telephone to determine which numbers correspond to which characters. If the
user enters one of those letters, display a message indicating that the value does not
match a number.Allow both uppercase and lowercase characters to be entered.Test your
program using your own phone number.
*USE CASE STATEMENTS
*USING VISUAL STUDIOS
* C # class
**NEED HELP PLEASE***
Explanation / Answer
Hi,
Use this, it is working perfectly. Hope it helps :)
class Program
{
static void Main(string[] args)
{
/*
People sometimes give their telephone number using one or more alphabetic characters.
Write a program that takes a single letter and displays the corresponding number. Look
at your telephone to determine which numbers correspond to which characters. If the
user enters one of those letters, display a message indicating that the value does not
match a number.Allow both uppercase and lowercase characters to be entered.Test your
program using your own phone number.
*USE CASE STATEMENTS
*USING VISUAL STUDIOS
* C # class
**NEED HELP PLEASE***
*/
Console.WriteLine("Please enter a letter");
string s = Console.ReadLine();
s = s.Substring(0, 1).ToUpper();
switch (s)
{
case "A":
case "B":
case "C": Console.WriteLine("2");
break;
case "D":
case "E":
case "F": Console.WriteLine("3");
break;
case "G":
case "H":
case "I": Console.WriteLine("4");
break;
case "J":
case "K":
case "L": Console.WriteLine("5");
break;
case "M":
case "N":
case "O": Console.WriteLine("6");
break;
case "P":
case "Q":
case "R":
case "S": Console.WriteLine("7");
break;
case "T":
case "U":
case "V": Console.WriteLine("8");
break;
case "W":
case "X":
case "Y":
case "Z": Console.WriteLine("9");
break;
default: Console.WriteLine("Invalid input");
break;
}
Console.Read();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.