Register Lost Password?  Cookie?
  The time now is 02:21 AM GMT -6.  
Banshee Network
 
Quick Links
 
 
GameBanshee Swag
Site Features
Submit News
News Archives
Join Our Staff
Forums
Community Blogs
Reviews
Previews
Interviews
Editorials
About GB
Advertise With Us!
Advertisement
 
Go Back   GameBanshee Forums > Forum Categories > Everything Else > Speak Your Mind

Reply
GameBanshee Forums  
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 03-20-2003, 05:13 PM
Member
 
Join Date: Feb 2003
Location: Where the wind takes me ..
Posts: 9
Send a message via ICQ to Eldaran Celuril
Help with computer program!

Hello everyone! I have QUITE the load of homework to do tonight, one portion of which being a computer program. I had the program nearly finished, and I emailed it to myself from school. Unfortunately, it didn't get through - I have no program, and it's due tomorrow. Mine was like 500 lines of code, though a friend of mine finished his in 100 .. If anyone has any creative ideas of how to do this program, I'd be much obliged:

- Has to be constructed in WinOOT
- Input a number up to seven digits long, e.g - 1523682
- Outputs the number converted to english, e.g - 1 million 5 hundred twenty three thousand six hundred eighty two

-> As you can see from the above examples, the english number is fairly basic; no punctuation, no 'and', etc!

Thanks in advance!

Last edited by Eldaran Celuril; 03-20-2003 at 05:23 PM..
Reply With Quote
  #2 (permalink)  
Old 03-20-2003, 05:58 PM
Member
 
Join Date: Feb 2003
Location: Where the wind takes me ..
Posts: 9
Send a message via ICQ to Eldaran Celuril
Sorry for the spam guys, it's just that I'm in dire need of assistance here, heh!

*Bumpity bump bump!*
Reply With Quote
  #3 (permalink)  
Old 03-20-2003, 07:00 PM
Aegis's Avatar
Exalted Member
 
Join Date: Dec 2000
Location: Soviet Canuckistan
Posts: 13,431
Send a message via MSN to Aegis
No worries, though be mindful of the recent bump rule

As for help, you might have some success posting a thread in the tech help as well... My extent of knowledge in WinOOT consists of making high pitched noises
Reply With Quote
  #4 (permalink)  
Old 03-20-2003, 07:05 PM
Member
 
Join Date: Feb 2003
Location: Where the wind takes me ..
Posts: 9
Send a message via ICQ to Eldaran Celuril
Sorry, didn't know there was a recent bump rule! I should probably make sure I'm up to date on this boards etiquette standards and standing policies! Thanks for the suggestion!
Reply With Quote
  #5 (permalink)  
Old 03-21-2003, 03:38 AM
Xandax's Avatar
Super Moderator
 
Join Date: Nov 2000
Location: Denmark
Posts: 13,438
Blog Entries: 12
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
__________________
"Software is too complicated, and too big, and too costly and too difficult to let users have anything to do with it!"
Svelmoe - Blogging about SQL, Technology and many other things
Reply With Quote
  #6 (permalink)  
Old 03-21-2003, 03:50 AM
Tamerlane's Avatar
Exalted Member
 
Join Date: May 2001
Location: Australia
Posts: 4,513
@ Xandax

Just had that sick feeling going through me. Thanks for reminding me to do my homework.

Never thought I'd live to see the day when Java is shown in all its horrible glory on SYM.
__________________
!
Reply With Quote
  #7 (permalink)  
Old 03-21-2003, 04:03 AM
Xandax's Avatar
Super Moderator
 
Join Date: Nov 2000
Location: Denmark
Posts: 13,438
Blog Entries: 12
Quote:
Originally posted by Tamerlane
@ Xandax

Just had that sick feeling going through me. Thanks for reminding me to do my homework.

Never thought I'd live to see the day when Java is shown in all its horrible glory on SYM.
no problem - anytime

BTW - just looked at the code and found out that both switch methods could be replaced by 2 array of strings wich would be much easier.

Making a string array holding "one"; two"; etc... and another "ten"; "twenty"..... and then using index-1 to get ahold of prober conversion - thus index of 1 subtracted 1 = 0, and then the arrayindex of 0 could be one or ten, depending on the array

Bah - hate finding easier ways just after I posted it
Actually I think I could shorten it down to about half the code with a few modifications
__________________
"Software is too complicated, and too big, and too costly and too difficult to let users have anything to do with it!"
Svelmoe - Blogging about SQL, Technology and many other things

Last edited by Xandax; 03-21-2003 at 04:25 AM..
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


 
      Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
© 2000-2009 GameBanshee.com