-
March 27th, 2013, 11:54 PM
#1
C# looping help!
Hi, I am not very good at programming, which you will be able to tell with how simple this problem is. (This is not an actual homework assignment, just a similar one so I can try to figure it out) But here is the problem.
People sometimes give their telephone numbers using one or more alphabetic characters. Write a program that accepts a 10 digit telephone number that may contain one or more alphabetic characters. Display the corresponding number using numbers. The numbers and letters are associated as follows on your telephone:
ABC: 2
DEF: 3
GHI: 4
JKL: 5
MNO: 6
PQRS: 7
TUV: 8
WXYZ: 9
If the user enters a character that is not on the telephone as a part of the number, display a message indicating that the value does not match a number. Allow both upper and lowercase characters to be entered.
Here is my embarassing work that I have so far. Like I said I am very bad at programming and would love some help! Feel free to start from scratch if you can't build off my work.
Code:
using System;
class DoLoop
{
public static void Main()
{
string myChoice;
do
{
Console.WriteLine("Telephone Key\n");
Console.WriteLine("ABC = 2");
Console.WriteLine("DEF = 3");
Console.WriteLine("GHI = 4");
Console.WriteLine("JKL = 5");
Console.WriteLine("MNO = 6");
Console.WriteLine("PQRS = 7");
Console.WriteLine("TUV = 8");
Console.WriteLine("WXYZ = 9");
Console.WriteLine("Please enter a 10 - digit telephone number using the letters above.");
myChoice = Console.ReadLine();
// Make a decision based on the user's choice
switch (myChoice)
{
case "ABC":
case "abc":
Console.WriteLine("2");
break;
case "DEF":
case "def":
Console.WriteLine("3");
break;
case "GHI":
case "ghi":
Console.WriteLine("4");
break;
case "JKL":
case "jkl":
Console.WriteLine("5");
break;
case "MNO":
case "mno":
Console.WriteLine("6");
break;
case "PQRS":
case "pqrs":
Console.WriteLine("7");
break;
case "TUV":
case "tuv":
Console.WriteLine("8");
break;
case "WXYZ":
case "wxyz":
Console.WriteLine("9");
break;
default:
Console.WriteLine("The value you have entered does not correspond with a number.", myChoice);
break;
}
// Pause to allow the user to see the results
Console.Write("press Enter key to continue...");
Console.ReadLine();
Console.WriteLine();
} while (myChoice != "Enter" && myChoice != "enter"); // Keep going until the user wants to quit
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|