I am trying to make a simple number to english words program and I've decided to use arrays.
Its not displaying the loop iteration values in tens2 array, as i have declared it in string array. what to do if i want to display string array tens2 with particular loop iterated index.
What do I need to change to fix that? Here's my code;
static void Main(string[] args)
{
Console.Write("Enter Number =");
string n = Console.ReadLine();
char[] num = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
string[] unit = new string[] { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
string[] tens = new string[] { "ten", "eleven", "twelve", "thirteen", "forteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
string[] tens2 = new string[] { "","twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
if (n.Length == 4)
{
for (int a = 0; a < num.Length; a++)
{
if (n[0].Equals(num[a]))
{
Console.Write("{0}" + " " + "Thousand", unit[a]);
break;
}
}
for (int a = 0; a < num.Length; a++)
{
if (n[1].Equals(num[a]))
{
Console.Write(" {0}" + " " + "Hundred", unit[a]);
break;
}
}
for (int a = 0; a < num.Length; a++)
{
if (n[2]=='1' && n[3].Equals(num[a]))
{
Console.Write(" {0}",tens[a+1]);
break;
}
else if (n[2].Equals('1') && n[3].Equals('0'))
{
Console.Write(" Ten");
break;
}
else if (n[2]!='1' && n[3].Equals(num[a]))
{
Console.Write(" {0}" , tens2[a]);
break;
}
}
for (int a = 0; a < num.Length; a++)
{
if ((n[3].Equals(num[a]) && (n[2]!='1')))
{
Console.Write(" {0}" , unit[a]);
break;
}
}
}
}
if (n.Length == 4)
condition at the beginning... – Shaul Apr 18 at 9:43