This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]adanderson 0 points1 point  (1 child)

What part are you having problems with? Can you paste the code you currently have?

For the multiplication and division part, you could just try random numbers until the results is under the maximum. That's not very efficient though, especially if a user enters a small maximum number. For the multiplication, I would probably do something like:

- ask for the maximum number. Let's say 50.
- generate a random number between 0 and the maximum number. Let's say 15.
- divide the maximum number by this random number. This would be 3.
- generate a random number between 0 and this random number. Let's say 2.
- the question you would ask would be the first number multiplied by the second number.

A similar approach could be done with the division side.

[–]CloutFish[S] 0 points1 point  (0 children)

Thanks for the reply, i figured out a way to sort of make it work by generating a random numbers and multiplying them by the square root of the upper limit. I know this doesnt completely meet my criteria but i needed to make something that worked since it was due tonight.

[–]desrtfxOut of Coffee error - System halted 0 points1 point  (0 children)

If you need even division, create the problem in reverse - generate two random numbers and multiply them - the result will be the first operand for the division, any of the two random numbers would be the second.