kyle schmelzer

kyle schmelzer

  • NA
  • 1
  • 1.5k

i need to change numbers and letters into numbers only

Dec 19 2013 7:14 AM

Hi there, new to this forum due to just learning C# this semester. Most of the semester was learning psuedo code, but now we're being tossed into code pretty quickly and i dont fully understand how to do it yet. I would ask my teacher, but he's retiring end of semester and doesnt care, wont respond to e-mails, is never in his office after/before hours etc. and is of no extra help. He gave us an assignment where we can use switch or if statements to do, but has never shown us switch's before. Soo after unsuccessfully trying to figure it out online with the msdn page and other tutorials, im posting for help.

I dont want somebody to outright do my homework for me, this is my future career, i need to understand how its done, but so far when i look online, or ask my friend whos a coder, all i see online is stuff i have never seen before, and my friend talks as if i know coding. I dont.

So to start off, heres my assignment so you know exactly what im trying for, and can answer my questions as best possible:

------

Businesses sometimes give their telephone numbers using alphabetic characters instead of (or in addition to) numerals. Write a program that accepts a telephone number string that may contain alphabetic characters, and displays the corresponding number with only numerals. 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

Your program should allow formatting characters (the left and right parentheses and the hyphen) in the displayed numeric string. If the user enters other characters that are not on the telephone dial, your program should ignore those characters. Allow both upper- and lower-case alphabetic characters to be entered. Your program can accept a longer string, but should display only up to ten numbers in the result.


-----

Now that you know what im looking to do, i have some questions. Ive only ever worked with Int and Decimal for like "prompts" i guess i would call them, i.e.

int phonenum;

Console.writeline( "Enter your phone number: ");

phonenum = int.parse(console.readline());


but now im adding in letters to the mix, i have a feeling that int and decimal wont work here. So no im curious as to how to start this.


Once that is settled, how to do i go apart breaking up the number so i can analyze the number digit by digit? Because if they entered a full 10 digit long number, wouldnt the program think its a number in the billions then, and not 10 individual digits? but more importantly, how do i break up a number like 800-cod-hard. I need to be able to allow the "-" as well as have the program realize the 800 isnt 800, but 8, 0, 0. Finally, what the hell is a switch, and how do i use it?


thanks for the help ahead of time guys, you're literally saving my life here.


Answers (1)