Have no idea what WinOOT is - but haveing a hard time to back down from programming problems I've solved it in Java
The code isn't very optimized and can be improved massive, also presently it requiers a 7 digit number as input, but that is easy to fix:
public class NumberInterp
{
private int input;
private int[] temp = new int[7];
private int temp2 = 1000000;
private int index = 6;
private String output;
public NumberInterp(int input)
{
this.input = input;
output = "";
}//end constructor
public String start()
{
while (input > 0)
{
temp[index] = input/temp2;
input = input%temp2;
index--;
temp2 = temp2/10;
}//end while
if (temp[6] > 0)
{ output += buildNumber1(temp[6]) + " million "; }
if (temp[5] > 0)
{ output += buildNumber1(temp[5]) + " hundred "; }
if (temp[4] > 0)
{ output += buildNumber2(temp[4]); }
if (temp[3] > 0)
{ output += buildNumber1(temp[3]); }
output += " thounsand ";
if (temp[2] > 0)
{ output += buildNumber1(temp[2]) + " hundred "; }
if (temp[1] > 0)
{ output += buildNumber2(temp[1]); }
if (temp[0] > 0)
{ output += buildNumber2(temp[0]); }
return output;
}
private String buildNumber1(int index)
{
switch (index)
{
case 1: return " one ";
case 2: return " two ";
case 3: return " three ";
case 4: return " four ";
case 5: return " five ";
case 6: return " six ";
case 7: return " seven ";
case 8: return " eight ";
case 9: return " nine ";
}//end switch
return null;
}//end method
private String buildNumber2(int index)
{
switch (index)
{
case 1: return " ten ";
case 2: return " twenty ";
case 3: return " thirty ";
case 4: return " forty ";
case 5: return " fifty ";
case 6: return " sixty ";
case 7: return " seventy ";
case 8: return " eighty ";
case 9: return " ninty ";
}//end switch
return null;
}//end method
}//end class
called with the parameter:
System.out.println(new NumberInterp(1234567).start());
it will return:
one million two hundred thirty four thounsand five hundred sixty seven
Basicall there are two "tricks" to this problem:
one you need to convert your input number so you know how many of "each" you have, eg 1 million and 2 hundred thousands.
This can easiestly (imo) be done with the modulus operation:
Interger divide in programming will return the number of times one integer is dividable by another eg:
10 / 3 = 3.
Modulus will return the remainder after a integer division:
10 % 3 = 1. (java and most other uses % as modulus, Pascal uses the keyword "mod")
This can be used to do the main calculation:
1234567 / 1000000 = 1
1234567 % 1000000 = 234567
Thus you know you have 1 millions and the remainder is 234567.
Running next modulus and integer dividing:
234567 / 100000 = 2
234567 % 100000 = 34567
and so on.
This is what happens in the first while loop.
Secondly you need to translate the 1, 2 etc into one, two, twenty etc.
This I use a swich structure for - it is basically just if constructions. And to avoid writing it all several times I've placed the code in methods: buildNumber1 and buildNumber2.
buildNumber1 returns a String with "one", "two" etc depending if the number is a 1,2 etc where as buildnumber2 returns "ten, twenty" etc.s if the number is a 1, 2....
Hope this helps a bit, if not I can try to explain it better
