Random numbers and division

D

DrNoose

I'm helping a friend with a program that uses random numbers. The user
tells the program how many questions to ask and the program will either
add, sub, multiply, or divide 2 numbers. The range of random numbers is
from 0-100. The problem, if there is one, is that many times the 2nd
number is larger when dividing the numbers causing you to have to give a
decimal answer. Is there a way to code the division case selection so
that it only returns a number without being a decimal?

Here is the code for case 4, which does the division of the random numbers.

**********************************************************************

Case 4

'Generate question.
sUserAnswer = InputBox("What is " & iOperand1 & _
" / " & iOperand2)

' Determine if user's answer was correct and add an
' appropriate item to the multi-column list box.
If Val(sUserAnswer) = iOperand1 / iOperand2 Then
lstResults.AddItem iOperand1 & " / " & _
iOperand2 & ";" & sUserAnswer & ";Correct"
Else
lstResults.AddItem iOperand1 & " / " & _
iOperand2 & ";" & sUserAnswer & ";Incorrect"
End If

Thanks!
 
V

Van T. Dinh

Well ... division in the set of natural numbers is not closed according to
the Number Theory whether the dividend is greater or smaller than the
divisor. For example:

Dividend / Divisor
31 / 5 = 6.2
5 / 8 = 0.625

(I think you referred to the second case dividend < divisor)

The results of both divisions are not in the set of natural numbers, i.e.
the operator / is not closed.

If you want to force this to a natural number, you will need to either round
or trucate the results. In Access, there is a integer division operator \
(backlash or slosh) which gives integer result. There are also functions
Int(), CInt(), CLng() and Round() to convert from a decimal value to an
integral value.

Check Access Help topics for these functions / operator ...
 
D

DrNoose

Van said:
Well ... division in the set of natural numbers is not closed according to
the Number Theory whether the dividend is greater or smaller than the
divisor. For example:

Dividend / Divisor
31 / 5 = 6.2
5 / 8 = 0.625

(I think you referred to the second case dividend < divisor)

The results of both divisions are not in the set of natural numbers, i.e.
the operator / is not closed.

If you want to force this to a natural number, you will need to either round
or trucate the results. In Access, there is a integer division operator \
(backlash or slosh) which gives integer result. There are also functions
Int(), CInt(), CLng() and Round() to convert from a decimal value to an
integral value.

Check Access Help topics for these functions / operator ...
Hi!

Thanks for your help!
 
M

Marshall Barton

DrNoose said:
I'm helping a friend with a program that uses random numbers. The user
tells the program how many questions to ask and the program will either
add, sub, multiply, or divide 2 numbers. The range of random numbers is
from 0-100. The problem, if there is one, is that many times the 2nd
number is larger when dividing the numbers causing you to have to give a
decimal answer. Is there a way to code the division case selection so
that it only returns a number without being a decimal?

Here is the code for case 4, which does the division of the random numbers.

**********************************************************************

Case 4

'Generate question.
sUserAnswer = InputBox("What is " & iOperand1 & _
" / " & iOperand2)

' Determine if user's answer was correct and add an
' appropriate item to the multi-column list box.
If Val(sUserAnswer) = iOperand1 / iOperand2 Then
lstResults.AddItem iOperand1 & " / " & _
iOperand2 & ";" & sUserAnswer & ";Correct"
Else
lstResults.AddItem iOperand1 & " / " & _
iOperand2 & ";" & sUserAnswer & ";Incorrect"
End If


How about changing the problem by using one of the random
numbers as the answer?

sUserAnswer = InputBox("What is " & _
iOperand1 * iOperand2 & " / " & iOperand2)
If Val(sUserAnswer) = iOperand1 Then
. . .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top