So the objective of this program is very similar to another C# homework problem (practically the same) but I am allowed to use arrays. I still need to set up the last error checking statement, but I wanted to finish and test with what I have so far. I have been working on this for 10+ hours and I am losing confidence every second. I do not know what I am doing wrong; my code always returns as a blank. Please help me point out my mistake so I can fix it. Thank you so much for your help.
class Program
{
static void Main(string[] args)
{
char digit1 = ' ', digit2 = ' ', digit3 = ' ', digit4 = ' ', digit5 = ' ', digit6 = ' ', digit7 = ' ';
int errorCode;
errorCode = GetInput(ref digit1, ref digit2, ref digit3,
ref digit4, ref digit5, ref digit6, ref digit7);
errorCode = ProcessInput(ref digit1, ref digit2, ref digit3,
ref digit4, ref digit5, ref digit6, ref digit7);
ShowResults(ref digit1, ref digit2, ref digit3,
ref digit4, ref digit5, ref digit6, ref digit7);
if (errorCode.Equals(-1))
{
Console.WriteLine("ERROR -1: INVALID NUMBER"); //add other error numbers later
}
Console.ReadLine();
}
static int GetInput(ref char digit1, ref char digit2, ref char digit3,
ref char digit4, ref char digit5, ref char digit6, ref char digit7)
{
string userInput;
int errorCode = 0;
Console.WriteLine("Please enter a seven digit number.");
userInput = Console.ReadLine();
if (userInput.Length == 8)
{
digit1 = userInput[0];
digit2 = userInput[1];
digit3 = userInput[2];
digit4 = userInput[4];
digit5 = userInput[5];
digit6 = userInput[6];
digit7 = userInput[7];
}
else if (userInput.Length != 7)
{
errorCode = -1;
}
return errorCode;
}
static int ProcessInput(ref char digit1, ref char digit2, ref char digit3,
ref char digit4, ref char digit5, ref char digit6, ref char digit7)
{
int errorCode = 0;
ToDigit(ref digit1);
ToDigit(ref digit2);
ToDigit(ref digit3);
ToDigit(ref digit4);
ToDigit(ref digit5);
ToDigit(ref digit6);
ToDigit(ref digit7);
if (digit1 == 5 && digit2 == 5 && digit3 == 5)
{
errorCode.Equals(-1);
}
else if (digit1 == 0)
{
errorCode.Equals(-1);
}
else
{
errorCode.Equals(0);
}
//if () will check for non-alphanumeric numbers
//{
//}
return errorCode;
}
static int ToDigit(ref char digit)
{
int errorCode = 0;
switch (digit) //was using a return statement per case, but getting same results.
{
case '0':
Console.WriteLine('0');
errorCode = 0;
break;
case '1':
Console.WriteLine('1');
errorCode = 0;
break;
case 'a':
case 'b':
case 'c':
Console.WriteLine('2');
errorCode = 0;
break;
case 'd':
case 'e':
case 'f':
Console.WriteLine('3');
errorCode = 0;
break;
case 'g':
case 'h':
case 'i':
Console.WriteLine('4');
errorCode = 0;
break;
case 'j':
case 'k':
case 'l':
Console.WriteLine('5');
errorCode = 0;
break;
case 'm':
case 'n':
case 'o':
Console.WriteLine('6');
errorCode = 0;
break;
case 'p':
case 'q':
case 'r':
case 's':
Console.WriteLine('7');
errorCode = 0;
break;
case 't':
case 'u':
case 'v':
Console.WriteLine('8');
errorCode = 0;
break;
case 'w':
case 'x':
case 'y':
case 'z':
Console.WriteLine('9');
errorCode = 0;
break;
default:
errorCode = -1;
break;
}
return errorCode;
}
static void ShowResults(ref char digit1, ref char digit2, ref char digit3,
ref char digit4, ref char digit5, ref char digit6, ref char digit7)
{
char[] digitConvert = new char[8];
digitConvert[0] = digit1;
digitConvert[1] = digit2;
digitConvert[2] = digit3;
digitConvert[3] = '-';
digitConvert[4] = digit4;
digitConvert[5] = digit5;
digitConvert[6] = digit6;
digitConvert[7] = digit7;
string finalNum = new string(digitConvert);
Console.WriteLine(finalNum.ToUpper());
}
}