Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / March 2007

Tip: Looking for answers? Try searching our database.

Random numbers and division

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DrNoose - 10 Mar 2007 00:15 GMT
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!
Van T. Dinh - 10 Mar 2007 04:21 GMT
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 ...

Signature

HTH
Van T. Dinh
MVP (Access)

> 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
[quoted text clipped - 26 lines]
>
> Thanks!
DrNoose - 10 Mar 2007 05:55 GMT
> 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
[quoted text clipped - 16 lines]
>
> Check Access Help topics for these functions / operator ...

Hi!

Thanks for your help!
Marshall Barton - 10 Mar 2007 15:08 GMT
>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
[quoted text clipped - 23 lines]
>                 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
    . . .

Signature

Marsh
MVP [MS Access]

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.