I am trying to make a simple number to english words program and I've decided to use arrays. However whenever I enter a number greater than 99, I get an error in the third if clause.. What do I need to change to fix that? Here's my code;
class Program
{
static void Main(string[] args)
{
string[] uptonineteen = {"Zero","One","Two","Three","Four",
"Five","Six","Seven","Eight","Nine","Ten",
"Eleven","Twelve","Thirteen","Fourteen","Fifteen",
"Sixteen","Seventeen","Eighteen","Nineteen"};
string[] ten = {"","","Twenty","Thirty","Forty","Fifty",
"Sixty","Seventy","Eighty","Ninety",};
Console.WriteLine(" ---------------");
int i = int.Parse(Console.ReadLine());
if (i < 20)
{
Console.WriteLine(uptonineteen[i]);
}
if (i < 100)
{
Console.WriteLine(ten[i / 10] + ((i % 10 > 0) ? "" + uptonineteen[i%10] : ""));
}
if (i <= 999)
{
object lenthree = ten[i / 100] + "hundred"+" " + ((i % 100 > 0) ? "and" +" "+ uptonineteen[i % 1000] : "");
Console.WriteLine(lenthree);
}
Console.ReadKey();
}
}
}
ten[i / 100]
and yeah noticed that and edited it but i still get the same error – Danny Petrunov Nov 23 '12 at 18:13