Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying to make maths program
#11
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:

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 Wink). 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
Reply
#12
i tried it it dont seem to work it just says 3 guesses left, it is suppose to be a maths program, and that doesent seem to give me a sum,i need the computer to generate sum and then loop the sum until the answer is wright, and then generate aanother some.
Sad
Reply
#13
It is frustrating when you spend 10 minutes writing a post... for nothing Undecided
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#14
That's "right".

PLEASE proofread/spell-check/add grammar to your post.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#15
im really sorry i didnt see all of your post thank you for your help , mate :oops:
Reply
#16
Quote:im really sorry i didnt see all of your post thank you for your help , mate :oops:
eh, no problem
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#17
I think he was possibly meaning thanks to Nath. :wink:
Reply
#18
i wasn't talkin to him about that =P ((Rereads own post and gets confused))
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#19
Quote:And you want all sums??? :roll: Relsoft style... Wink

LOL.

Big Grin
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#20
for the bit that says random number would i put in
Code:
RND = .4828411
10 * RND = 4.828411
INT(10*RND) = 4

and i need some help on getting it to print the sum and the users input, any help?

thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)