Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Simple Question About Random Numbers In Functions

Author
Message
Brendo
18
Years of Service
User Offline
Joined: 14th Sep 2006
Location: Australia
Posted: 15th Sep 2006 06:24
Hi, I am totally new to DB. I have written a short program that generates 6 number lotto games.

The problem is that if I run the contents of the MyNumbers function on their own the outcome is correct, but if I include the MyNumbers function inside the NextGame function it adds a zero on the end of my set of 6 numbers. eg. 2 45 23 15 25 11 0
Please help. Thanks

cls
randomize timer()
print "Welcome to Brendos Winning Lotto Number Generator"
print
print "Enter the number of games you wish to play: ";
INPUT A
sleep 500
print "Calculating winning numbers..."
print
sleep 500
print "Please Wait..."
sleep 1000
print "Your winning numbers for this week are....";
print

NextGame(A)
MyNumbers()rem...This set of numbers is correct, No 0 at the end.

END


FUNCTION NextGame(A)
for T= 1 to A
print "Game ";T;":";MyNumbers()
next T
ENDFUNCTION

rem...This function generates a set of 6 numbers, but adds a 0 on rem...the end.
FUNCTION MyNumbers()
for T= 1 to 6
NextNumber= rnd(44)+1
print NextNumber;" ";
next T
ENDFUNCTION]
Brendo
18
Years of Service
User Offline
Joined: 14th Sep 2006
Location: Australia
Posted: 15th Sep 2006 10:39
I worked it out. Instead of having two functions I reduced it to one, and have now moved on to adding other features. I would still like to hear anybodies solutions however as I am new to coding and would appreciate help with simplifing my code. Thanks.
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 15th Sep 2006 11:59
Corrected code. Reason is that you printed the result of a function, ie MyNumbers() - functions normally return a value, in this case 0. So if you force it to return "" all is ok.



Boo!
Brendo
18
Years of Service
User Offline
Joined: 14th Sep 2006
Location: Australia
Posted: 15th Sep 2006 23:45
Thanks

Login to post a reply

Server time is: 2024-11-26 12:33:54
Your offset time is: 2024-11-26 12:33:54