guyz d activity is to let the user input a number and the program should output a string version of it...
i already got it but wondering if this can be shorter...cause its a very long code...tnx for those who would reply
string[] ones = new string[]{"one","two","three","four","five","six","seven"," eight","nine"};
string[] tens = new string[]{"ten","twenty","thirty","fourty","fifty","sixty", "seventy","eighty","ninety"};
string h,o,t;
Console.Write("Enter Number: ");
string num = Console.ReadLine;
if (num.length==3)
{
for(y=0;y<=9;y++)
{
if(num[0]==y)
{
h= ones[y] + " " + "hundred";
}
if(num[1]==y)
{
t = tens [y] + " ";
}
else
{
t= "";
}
if(num[2]==y)
{
o= ones[y];
}
}
}
if (num.length==2)
{
for(y=0;y<=9;y++)
{
if(num[0]==y)
{
t = tens [y] + " ";
}
else
{
t= "";
}
if(num[1] == y)
{
o= ones[y];
}
}
}
else
{
for(y=0;y<=9;y++)
{
if(num[0] == y)
{
o= ones[y];
}
}
}
Console.Write(h + " " + t + " " + o);
Console.ReadLine();
P.S. Before receiving all the flames i would just like to say i did my best..its the shortest way i can think of...but just incase there is a better way it would be nice to know so ill learn more