Results 1 to 5 of 5

Thread: Masic math skills

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    USA
    Posts
    1

    Smile Masic math skills

    I am a VB beginner. I am working on a small project for kids to improve math basic skills ( subtraction, division …etc). I would appreciate it if any one could help on these questions:
    FIRST:
    I am writing this code

    FirstNumber = Int((1 * Rnd) + 1)
    lblFirstNumber.Caption = FirstNumber

    SecondNumber = Int((1 * Rnd) + 1)
    lblSecondNumber.Caption = SecondNumber

    bothNumbers= FirstNumber + SecondNumber


    How can I write a code so that FirstNumber OR SecondNumber to be restricted to interval (e.g. >=1 but <5)

    SECOND:
    How can I write the code so that bothNumbers would be ONLY positive ( e.g. >= 1) in case of Subtraction or Division.
    Third:
    How Can I add MDI file as music background that would keep looping till FORM Unloaded

    FOUR: What code can I write to ADJUST the Volume of such Music?
    Thank you

    Mike
    [email protected]

  2. #2
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    Re: Masic math skills

    Originally posted by mehlayel

    FIRST:
    I am writing this code

    FirstNumber = Int((1 * Rnd) + 1)
    lblFirstNumber.Caption = FirstNumber

    SecondNumber = Int((1 * Rnd) + 1)
    lblSecondNumber.Caption = SecondNumber

    bothNumbers= FirstNumber + SecondNumber


    How can I write a code so that FirstNumber OR SecondNumber to be restricted to interval (e.g. >=1 but <5)

    SECOND:
    How can I write the code so that bothNumbers would be ONLY positive ( e.g. >= 1) in case of Subtraction or Division.
    Third:
    How Can I add MDI file as music background that would keep looping till FORM Unloaded

    FOUR: What code can I write to ADJUST the Volume of such Music?
    [/email]
    THREE & FOUR: Unless you've cross posted, I'd advise you to ask these in General VB Questions .

    FIRST: Since the code you wrote automatically sets FirstNumber =1 and SecondNumber =1, they already are in the range you requested, just limited to 1 element of that range.

    If you want SecondNumber and FirstNumber to be each a random number between 1 and 5, then the code should be:
    VB Code:
    1. Randomize
    2. FirstNumber = Int(Rnd*5 + 1)
    3. SecondNumber = Int(Rnd*5 + 1)

    SECOND: To do this, you have to actually place furthur conditions on FirstNumber and SecondNumber, IE... Instead of the above, This would work:
    VB Code:
    1. Randomize
    2. FirstNumber = 1
    3. SecondNumber = 2
    4. While FirstNumber < SecondNumber
    5.     FirstNumber = Int(Rnd*5 + 1)
    6.     SecondNumber = Int(Rnd*5 + 1)
    7. Wend

    -Hope this Helps
    -Lou

  3. #3
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    For the looping midi thing, check out the link in my sig for an example.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Re: Masic math skills

    Originally posted by mehlayel

    FIRST:
    I am writing this code

    FirstNumber = Int((1 * Rnd) + 1)
    lblFirstNumber.Caption = FirstNumber

    SecondNumber = Int((1 * Rnd) + 1)
    lblSecondNumber.Caption = SecondNumber

    bothNumbers= FirstNumber + SecondNumber


    How can I write a code so that FirstNumber OR SecondNumber to be restricted to interval (e.g. >=1 but <5)

    A suggestion: Post your code in [vbcode] & [/vbcode] tags
    Change it to this:
    VB Code:
    1. Randomize
    2. FirstNumber = Int((5 * Rnd) + 1)
    3.     lblFirstNumber.Caption = FirstNumber
    4.    
    5.     SecondNumber = Int((5 * Rnd) + 1)
    6.     lblSecondNumber.Caption = SecondNumber
    7.  
    8. bothNumbers= FirstNumber + SecondNumber

    That creates a random number between 5 and 1 for both FirstNumber and SecondNumber

  5. #5
    Member
    Join Date
    Aug 2001
    Posts
    51
    When randomly generating the numbers for subtraction you would want to take into account the value of FirstNumber when randomly generating SecondNumber. For example:

    VB Code:
    1. FirstNumber = Int(Rnd * 8) ' The range is 0-7
    2. SecondNumber = Int(Rnd * (FirstNumber)) 'The range is 0-(FirstNumber - 1)

    This results in the subtraction having a result range of 0 - 7, ie never below zero.

    To get division greater than zero is easy, just make both the numerator (top number) and denominator (bottom number) both positive. I suspect you would want the result to be an integer though? This is a bit harder.

    You could use trail and error to repeatedly generate numerators and denominators until a pair are found for which the result is an integer. Using a bit of algrebra and formula re-arrangement will show an easier way to generate questions though:

    we start with:
    numerator / denominator = result

    re-arrange to:
    denominator * result = numerator

    Re-arranging this makes it obvious (at least to me) that it would be easier to generate a random result and denominator and calculate the numerator from there. For example a range of 1-5 for denominator and 1-5 for result would have a range of 1-25 for the numerator. You could also make the maximum value of result depend on the value of denominator to limit the upper range of the numerator.

    Also, you might find this useful - according to MSDN:
    To produce random integers in a given range, use this formula:

    Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

    Here, upperbound is the highest number in the range, and lowerbound is the lowest number in the range.
    Hope that all makes sense and is useful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width