Answered by:
random generating qs

Question
-
Hi..........um im working on a basic random maths generating project were the computer generates two random numbers which you have to add etc. (e.g. 1*5). Im stuck trying to generate equations with random maths signs +*/-. P.s. The division qs must be divisible into a whole number please helppppppppppppMonday, August 31, 2009 11:55 AM
Answers
-
Something like this:
num1=math.GetRandomNumber(10) num2=math.GetRandomNumber(10) operation=math.GetRandomNumber(4) If operation=1 Then '+ EndIf If operation=2 Then '- EndIf If operation=3 Then '/ tempnum=num1 result=num1*num2 num1=result result=tempnum op_char="/" EndIf If operation=4 Then '* result=num1*num2 op_char="*" EndIf TextWindow.Write(num1) TextWindow.Write(op_char) TextWindow.Write(num2) TextWindow.Write("=")
you have to write own routines for - and + operations and you have to get result from user and check is it correct.
Hope it helps :)
Grzesio- Proposed as answer by Flurng Friday, September 18, 2009 4:07 PM
- Marked as answer by Ed Price - MSFTMicrosoft employee Tuesday, October 23, 2012 7:49 AM
Monday, August 31, 2009 12:48 PM -
Try to think how your code should work.
What you need to do when you know operation and two numbers.
If you know this - we can try to prepare some code for your "recipe". :)
Look at MY sample code (not the code in your post) and try to determine when (and how) we are displaying numbers and sign.
Grzesio- Marked as answer by Ed Price - MSFTMicrosoft employee Tuesday, October 23, 2012 7:49 AM
Wednesday, September 2, 2009 11:21 AM
All replies
-
Something like that ?
Sub GenerateNewExercice
FirstNum = Math.Random(10) ' number from 1 to 10
SecondNum = Math.Random(10) 'number from 1 to 10
Operation = Math.Random(4) ' number from 1 to 4
If Operation = 1 Then
Result = FirstNum + SecondNum
Operator = "+"
ElseIf Operation = 2 Then
Result = FirstNum - SecondNum
Operator = "-"
...
ElseIf Operation = 4 Then
Result = FirstNum / SecondNum
If Result <> Math.Round(Result) Then ' The division is not valid
GenerateNewExercice()
EndIf
Operator = "/"
EndIf
EndSub
Must by adapted to your needs, it's just a stub here.
Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extensionMonday, August 31, 2009 12:45 PM -
Something like this:
num1=math.GetRandomNumber(10) num2=math.GetRandomNumber(10) operation=math.GetRandomNumber(4) If operation=1 Then '+ EndIf If operation=2 Then '- EndIf If operation=3 Then '/ tempnum=num1 result=num1*num2 num1=result result=tempnum op_char="/" EndIf If operation=4 Then '* result=num1*num2 op_char="*" EndIf TextWindow.Write(num1) TextWindow.Write(op_char) TextWindow.Write(num2) TextWindow.Write("=")
you have to write own routines for - and + operations and you have to get result from user and check is it correct.
Hope it helps :)
Grzesio- Proposed as answer by Flurng Friday, September 18, 2009 4:07 PM
- Marked as answer by Ed Price - MSFTMicrosoft employee Tuesday, October 23, 2012 7:49 AM
Monday, August 31, 2009 12:48 PM -
I dont know where to insert it... I tried putting it in diffrent places but it either ends up like
-
156
Press any character to continue...
for this phrase i edited it
If operation=1 Then
Textwindow.Writeline ("+")
EndIf
If operation=2 Then
Textwindow.Writeline ("-")
EndIf
If operation=3 Then
Textwindow.Writeline ("/")
tempnum=num1
result=num1*num2
num1=result
result=tempnum
op_char="/"
EndIf
If operation=4 Then
Textwindow.Writeline ("*")
result=num1*num2
op_char="*"
EndIf
Tuesday, September 1, 2009 9:19 AM -
Do not touch section for operation 3 and operation 4. They are ready.
Try to make secions for operation 1 and 2 similar and write some code for getting an answer, checking if it's correct etc.
GrzesioTuesday, September 1, 2009 9:24 AM -
whats wrong with operation 1 and 2Wednesday, September 2, 2009 9:33 AM
-
Try to think how your code should work.
What you need to do when you know operation and two numbers.
If you know this - we can try to prepare some code for your "recipe". :)
Look at MY sample code (not the code in your post) and try to determine when (and how) we are displaying numbers and sign.
Grzesio- Marked as answer by Ed Price - MSFTMicrosoft employee Tuesday, October 23, 2012 7:49 AM
Wednesday, September 2, 2009 11:21 AM