Shaker AlSalem

Shaker AlSalem

  • NA
  • 25
  • 18k

Cant locate my error in this code

Feb 23 2012 1:09 AM
Cant figure out why it giving me error at line 116, can anyone please tell me where did i go wrong? 
Thanks!


Some people provide phone numbers using one or more alphabetic characters. Write a method that will take a single letter and display the corresponding number. You may want to take a look at your telephone for this...an old telephone that is, your smartphone will not work for this. If the character does not correspond to any number display a message stating the fact. If the character is a numerical digit, the same numerical digit must be returned. Allow upper case and lowercase characters to be accepted.  In the main, write a small application that will ask the user for a "fancy" phone number, and by calling the method, display the equivalent in just numerical digits. 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shaker
{
class Program
{
public static void Main()
{

Console.Write("Enter Phone Number: ");
convertcharacter1();

}

private static void convertcharacter1()
{

int i = 0;
string character1 = Console.ReadLine();
Console.WriteLine(character1);

while (true)
{
char character = char.Parse(character1.Substring(i, 1).ToLower());

switch (character)
{
case '0':
character1 += "0";
break;

case '1': character1 += "1";
break;

case '2': character1 += "2";
break;

case '3': character1 += "3";
break;

case '4': character1 += "4";
break;

case '5': character1 += "5";
break;

case '6': character1 += "6";
break;

case '7': character1 += "7";
break;

case '8': character1 += "8";
break;

case '9': character1 += "9";
break;

case '-': character1 += "-";
break;

case 'a':
case 'b':
case 'c': character1 += "2";
break;

case 'd':
case 'e':
case 'f': character1 += "3";
break;

case 'g':
case 'h':
case 'i': character1 += "4";
break;

case 'j':
case 'k':
case 'l': character1 += "5";
break;

case 'm':
case 'n':
case 'o': character1 += "6";
break;

case 'p':
case 'q':
case 'r':
case 's': character1 += "7";
break;

case 't':
case 'u':
case 'v': character1 += "8";
break;

case 'w':
case 'x':
case 'y':
case 'z': character1 += "9";
break;


i++;


}


}
}
}

Answers (15)