|
-
Oct 18th, 2001, 05:26 AM
#1
Thread Starter
New Member
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]
-
Oct 18th, 2001, 08:39 AM
#2
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:
Randomize
FirstNumber = Int(Rnd*5 + 1)
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:
Randomize
FirstNumber = 1
SecondNumber = 2
While FirstNumber < SecondNumber
FirstNumber = Int(Rnd*5 + 1)
SecondNumber = Int(Rnd*5 + 1)
Wend
-Hope this Helps
-Lou
-
Oct 19th, 2001, 02:59 AM
#3
Fanatic Member
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 
-
Oct 19th, 2001, 05:47 AM
#4
Conquistador
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:
Randomize
FirstNumber = Int((5 * Rnd) + 1)
lblFirstNumber.Caption = FirstNumber
SecondNumber = Int((5 * Rnd) + 1)
lblSecondNumber.Caption = SecondNumber
bothNumbers= FirstNumber + SecondNumber
That creates a random number between 5 and 1 for both FirstNumber and SecondNumber
-
Oct 22nd, 2001, 03:23 AM
#5
Member
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:
FirstNumber = Int(Rnd * 8) ' The range is 0-7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|