-
December 1st, 2011, 03:43 PM
#1
Please don't cringe
Now, I know, you didn't think neanderthals still existed, but you may be persuaded otherwise after reading this. So, I need to create a program that will take a letter and give the corresponding number from a phone keypad. For example, I enter a b or c, and it gives me 2...and so on. I figured I could use a switch statement. However, I soon realized the whole (can't convert string to bool), so my question is...how do I take the string input and match it to each of the cases? You don;t have to tell me how to do it, just give a hint or two. As usual, you're all very helpful and I appreciate any response. (I realize there is probably a lot of other things wrong with the code, but I'll take it one step at a time).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string option;
while (option)
{
DisplayMenu();
option = (Console.ReadLine());
switch (option)
{
case "a,b,c":
Console.WriteLine("2");
break;
case "d,e,f":
Console.WriteLine("3");
break;
case "g,h,i":
Console.WriteLine("4");
break;
case "j,k,l":
Console.WriteLine("5");
break;
case "m,n,o":
Console.WriteLine("6");
break;
case "p,q,r,s":
Console.WriteLine("7");
break;
case "t,u,v":
Console.WriteLine("8");
break;
case "w,x,y,z":
Console.WriteLine("9");
break;
}
}
}
static void DisplayMenu()
{
Console.WriteLine("Enter a letter:");
}
}
}
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
|