01-21-2004, 07:05 PM
Yup, let's hint.
First you need to generate a random number. Whitetiger's formula is somewhat unaccurate, it should be INT(RND*(high-low+1))+low, but let's explain:
a) RND returns a random number each time it is used. The random number is in the range from 0 to 1 with decimals (this is, 0.324334, 0.88888, 0.67346 etcetera). If you want it (for example) to be from 0 to 10 you have to multiply by 10. The INT bit makes the number a integer, eliminating the decimals:
For example:
b) just multiplying RND for a number and then applying INT will only give you random numbers between 0 and the number you multiplied minus one. (I.E. INT(10*RND) will return numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 in random order). If you wanna, for example, have random numbers between 7 and 21, for example, you have to do some calculations:
b1) First you have to figure out how many different numbers there are. From 7 to 21 you have 21-7+1=15 different numbers (count with your fingers and you'll find out ). That's the number you have to multiply RND by.
b2) INT(15*RND) will give numbers from 0 to 15, just add 7: INT(15*RND)+7 and you'll get numbers from 7 to 21. Just some maths.
Now you should be able to figure out the formula: redo the steps I've posted and you'll find it:
To make what you want, you have to generate two random numbers, then add them and do your loop until the user enters the number you calculated.
Here is a schematic pseudocode. Try to understand how it works and then translate it to QB and post here:
Good luck!
First you need to generate a random number. Whitetiger's formula is somewhat unaccurate, it should be INT(RND*(high-low+1))+low, but let's explain:
a) RND returns a random number each time it is used. The random number is in the range from 0 to 1 with decimals (this is, 0.324334, 0.88888, 0.67346 etcetera). If you want it (for example) to be from 0 to 10 you have to multiply by 10. The INT bit makes the number a integer, eliminating the decimals:
For example:
Code:
RND = .4828411
10 * RND = 4.828411
INT(10*RND) = 4
b) just multiplying RND for a number and then applying INT will only give you random numbers between 0 and the number you multiplied minus one. (I.E. INT(10*RND) will return numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 in random order). If you wanna, for example, have random numbers between 7 and 21, for example, you have to do some calculations:
b1) First you have to figure out how many different numbers there are. From 7 to 21 you have 21-7+1=15 different numbers (count with your fingers and you'll find out ). That's the number you have to multiply RND by.
b2) INT(15*RND) will give numbers from 0 to 15, just add 7: INT(15*RND)+7 and you'll get numbers from 7 to 21. Just some maths.
Now you should be able to figure out the formula: redo the steps I've posted and you'll find it:
Code:
randomNumber% = INT ( (high%-low%+1) * RND ) + low%
To make what you want, you have to generate two random numbers, then add them and do your loop until the user enters the number you calculated.
Here is a schematic pseudocode. Try to understand how it works and then translate it to QB and post here:
Code:
// PSEUDOCODE
s1 = RANDOM NUMBER BETWEEN 1 AND 10
s2 = RANDOM NUMBER BETWEEN 1 AND 10
sum = s1 + s2
BEGIN LOOP
ASK USER FOR INPUT
LOOP WHILE USER'S INPUT <> sum
Good luck!
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i