# Need some logic help with my math generator

## Recommended Posts

I am trying to generate math tasks about limits. My code is working but I want it output only tasks which answer type is int (-49/4 is float but -49 would be int) How could I code that check?

My code generated me (2*x^3+2*x^2-2*x-1)*(49-x^2)/(x^2+4) which solves to -49/4 which is float.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Math.au3>

\$var = "x"
\$maxpow = 1
\$Actions = 3
Dim \$Funclist[3]
\$Funclist[0] = 'GenSumDifferenceOfTwoCubes()'
\$Funclist[1] = 'SumDifferenceOfTwoSquares()'
\$Funclist[2] = 'Rndf("%dx^3 ± %dx^2 ± %dx ± %d")'
dim \$ActionList[3]

#Region ### START Koda GUI section ### Form=
\$Form1 = GUICreate("Lim gen", 332, 268, 192, 124)
\$Label1 = GUICtrlCreateLabel("Lim", 30, 40, 37, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Century Schoolbook")
GUICtrlSetColor(-1, 0x000000)
\$Label2 = GUICtrlCreateLabel("X ->", 30, 60, 23, 17)
\$Sub = GUICtrlCreateCheckbox("Sub", 90, 30, 40, 17)
\$Mult = GUICtrlCreateCheckbox("Mult", 90, 50, 40, 17)
\$Div = GUICtrlCreateCheckbox("Div", 90, 70, 40, 17)
\$pow = GUICtrlCreateCheckbox("pow", 90, 90, 40, 17)
\$Sqrt = GUICtrlCreateCheckbox("Sqrt", 90, 110, 40, 17)
\$Abs = GUICtrlCreateCheckbox("Abs", 90, 130, 40, 17)
\$Input1 = GUICtrlCreateInput("N", 50, 60, 26, 21)
\$Generate = GUICtrlCreateButton("Generate", 10, 155, 75, 25, \$WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
\$nMsg = GUIGetMsg()
Switch \$nMsg
Case \$GUI_EVENT_CLOSE
Exit
Case \$Generate
\$String = ""
For \$repeat = 1 To 10
For \$nr = 0 To \$Actions -1
\$ActionList[\$nr] =  Execute(ChooseRandom(\$Funclist))
Next
ConsoleWrite(\$ActionList[0]&RndMultDiv()&\$ActionList[1]&RndMultDiv()&\$ActionList[2]&@CRLF)
Next
EndSwitch
WEnd

Func ChooseRandom(\$aArray)
\$maxarray = UBound(\$aArray) -1
Return \$aArray[Random(0,\$maxarray,1)]
EndFunc

Func GenSumDifferenceOfTwoCubes()
Local \$Str
\$prnd = Random(1, \$maxpow, 1)
\$prnd = _Max(1, \$prnd)
\$p = \$prnd * 3
\$n = Random(1, 5, 1)
\$xpos = Random(0, 1, 1)
\$rndplussminus = Random(0, 1, 1)
If \$rndplussminus = 0 Then
\$rndplussminus = " - "
Else
\$rndplussminus = " + "
EndIf
If \$xpos = 0 Then
\$Str = "( x^" & \$p & \$rndplussminus & \$n ^ (3 * \$prnd) & " )"
Else
\$Str = "( " & \$n ^ (3 * \$prnd) & \$rndplussminus & "x^" & \$p & " " & ")"
EndIf
If StringInStr(\$Str, "x^0") Then \$Str = StringReplace(\$Str, "x^0", 1)
Return \$Str
EndFunc   ;==>GenSumDifferenceOfTwoCubes

Func SumDifferenceOfTwoSquares()
Local \$Str
\$prnd = Random(1, \$maxpow, 1)
\$prnd = _Max(1, \$prnd)
\$p = \$prnd * 2
\$n = Random(1, 9, 1)
\$xpos = Random(0, 1, 1)
\$rndplussminus = Random(0, 1, 1)
If \$rndplussminus = 0 Then
\$rndplussminus = " - "
Else
\$rndplussminus = " + "
EndIf
If \$xpos = 0 Then
\$Str = "( x^" & \$p & \$rndplussminus & \$n ^ (2 * \$prnd) & " )"
Else
\$Str = "( " & \$n ^ (2 * \$prnd) & \$rndplussminus & "x^" & \$p & " " & ")"
EndIf
If StringInStr(\$Str, "x^0") Then
\$Str = StringReplace(\$Str, "x^0", 1)
EndIf
Return \$Str
EndFunc   ;==>SumDifferenceOfTwoSquares

Func Rndf(\$Str)
\$i = 1
While StringInStr(\$Str, "±")
\$Str = StringReplace(\$Str, "±", RndPlusMinus(), \$i)
\$i += 1
WEnd
\$i = 1
While StringInStr(\$Str, "%d")
\$Str = StringReplace(\$Str, "%d", Random(1,3,1), \$i)
\$i += 1
WEnd
Return "( "&StringReplace(\$Str,"1x^","x^")&" )"
EndFunc

Func RndPlusMinus()
\$rndplussminus = Random(0, 1, 1)
If \$rndplussminus = 0 Then
\$rndplussminus = "-"
Else
\$rndplussminus = "+"
EndIf
Return \$rndplussminus
EndFunc   ;==>RndPlusMinus

Func RndMultDiv()
\$rndplussminus = Random(0, 1, 1)
If \$rndplussminus = 0 Then
\$rndplussminus = "/"
Else
\$rndplussminus = "*"
EndIf
Return \$rndplussminus
EndFunc   ;==>RndPlusMinus

edited

##### Share on other sites

Hello E1M1,

did you try Int()?

Regards,

Hannes

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

##### Share on other sites

Or, if you want to test that, did you try IsInt(), IsFloat(), etc?

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

##### Share on other sites

I guess I didn't explain well enough. I want to check if answer is int after I solve it. I know IsInt() but how do I make it get answers to use with IsInt()?

http://en.wikipedia.org/wiki/Limit_%28mathematics%29

edited

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...