Underdogger Posted March 2, 2013 Share Posted March 2, 2013 (edited) I don't know what wrong with my code is? When I start guessing, but it appeared "Must be in the Range of..." looping . I don't know what the problem with my logic is ? While 1 Local $setMax = InputBox("","Input Max Num:") Local $setMin = InputBox("","Input Min Num:") Local $MXtemp = $setMax Local $MNtemp = $setMin $RandomNum = Random($setMin, $setMax, 1) ;debug MsgBox(0, "", $RandomNum) Do $Guess = InputBox("","Guess Number:") If @error <> 1 Then If $Guess < $setMax And $Guess > $setMin Then If $Guess < $RandomNum Then $setMin = $Guess $MNtemp = $setMin MsgBox(0, "", "Too high..." & @CRLF & $setMin & "-" & $setMax) ElseIf $Guess > $RandomNum Then $setMax = $Guess $MXtemp = $setMax MsgBox(0, "", "Too low..." & @CRLF & $setMin & "-" & $setMax) Else MsgBox(0, "", "Excellent!" & @CRLF & "The Number is:" & $RandomNum) ExitLoop EndIf Else $setMax = $MXtemp $setMin = $MNtemp MsgBox(0, "", "Must be in the Range of" & @CRLF & $setMin & " and "& $setMax) EndIf Else ExitLoop EndIf Until $Guess == $RandomNum $again = MsgBox(1, "", "Continue?") If $again == 2 Then ExitLoop WEnd And this is the 1st ver. of this code... It can be run normally..↓ While 1 Dim $High = 100, $MXtemp = 100, $Low = 1, $MNtemp = 1 $RandomNum = Random(1, 100, 1) Do $Guess = InputBox("", "Guess Number:") If @error <> 1 Then If $Guess < $High And $Guess > $Low Then If $Guess < $RandomNum Then $Low = $Guess $MNtemp = $Low MsgBox(0, "", "Too low..." & @CRLF & $Low & "-" & $High) ElseIf $Guess > $RandomNum Then $High = $Guess $MXtemp = $High MsgBox(0, "", "Too high..." & @CRLF & $Low & "-" & $High) Else MsgBox(0, "", "Excellent!" & @CRLF & "The Number is:" & $RandomNum) ExitLoop EndIf Else $High = $MXtemp $Low = $MNtemp MsgBox(0, "", "Must be in the Range of" & @CRLF & $Low & " and " & $High) EndIf Else ExitLoop EndIf Until $Guess == $RandomNum $again = MsgBox(1, "", "Continue?") If $again == 2 Then ExitLoop WEnd Edited March 2, 2013 by Underdogger Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 2, 2013 Moderators Share Posted March 2, 2013 Underdogger, What does it not do that you think it should? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Underdogger Posted March 2, 2013 Author Share Posted March 2, 2013 (edited) Underdogger,What does it not do that you think it should? M23When I start guessing, but it appeared "Must be in the Range of..." looping .I don't know what the problem with my logic is ?My 1st ver. it can run normally..but while I added two inputboxs on top, It got error.. Edited March 2, 2013 by Underdogger Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 2, 2013 Moderators Share Posted March 2, 2013 Underdogger, Your logic was seriously flawed, but rather than go into huge detail about why I have rewritten it for you: While 1 Local $setMax = InputBox("", "Input Max Num:") Local $setMin = InputBox("", "Input Min Num:") $RandomNum = Random($setMin, $setMax, 1) While 1 $Guess = InputBox("", "Guess Number:") If @error <> 1 Then If $Guess = $RandomNum Then MsgBox(0, "", "Excellent!" & @CRLF & "The Number is:" & $RandomNum) If MsgBox(1, "", "continue?") = 2 Then Exit Else ExitLoop EndIf Else Select Case $Guess > $setMax Or $Guess < $setMin MsgBox(0, "", "Must be in the Range of" & @CRLF & $setMin & " and " & $setMax) Case $Guess < $RandomNum MsgBox(0, "", "Too low..." & @CRLF & $setMin & "-" & $setMax) Case $Guess > $RandomNum MsgBox(0, "", "Too high..." & @CRLF & $setMin & "-" & $setMax) EndSelect EndIf EndIf WEnd WEnd Can you follow that logic? Please ask if not. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Developers Jos Posted March 2, 2013 Developers Share Posted March 2, 2013 Why are you doing this in your logic?: $setMin = $Guess $MNtemp = $setMin SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Underdogger Posted March 2, 2013 Author Share Posted March 2, 2013 Why are you doing this in your logic?: $setMin = $Guess $MNtemp = $setMin Avoiding who set wrong number out of range... Link to comment Share on other sites More sharing options...
Underdogger Posted March 2, 2013 Author Share Posted March 2, 2013 (edited) Underdogger, Your logic was seriously flawed, but rather than go into huge detail about why I have rewritten it for you: While 1 Local $setMax = InputBox("", "Input Max Num:") Local $setMin = InputBox("", "Input Min Num:") $RandomNum = Random($setMin, $setMax, 1) While 1 $Guess = InputBox("", "Guess Number:") If @error <> 1 Then If $Guess = $RandomNum Then MsgBox(0, "", "Excellent!" & @CRLF & "The Number is:" & $RandomNum) If MsgBox(1, "", "continue?") = 2 Then Exit Else ExitLoop EndIf Else Select Case $Guess > $setMax Or $Guess < $setMin MsgBox(0, "", "Must be in the Range of" & @CRLF & $setMin & " and " & $setMax) Case $Guess < $RandomNum MsgBox(0, "", "Too low..." & @CRLF & $setMin & "-" & $setMax) Case $Guess > $RandomNum MsgBox(0, "", "Too high..." & @CRLF & $setMin & "-" & $setMax) EndSelect EndIf EndIf WEnd WEnd Can you follow that logic? Please ask if not. M23 But I want to let other know the range of two numbers, Exp. The correct random Num is 45 (min1 - max100). while I input 55, it will tell other "1-55" and start guessing between those two numbers... Edited March 2, 2013 by Underdogger Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 2, 2013 Moderators Share Posted March 2, 2013 Underdogger, Understood - so this should do the trick: While 1 Local $setMax = InputBox("", "Input Max Num:") Local $setMin = InputBox("", "Input Min Num:") Local $GuessMax = $setMax Local $GuessMin = $setMin $RandomNum = Random($setMin, $setMax, 1) While 1 $Guess = InputBox("", "Guess Number:") If @error <> 1 Then If $Guess = $RandomNum Then MsgBox(0, "", "Excellent!" & @CRLF & "The Number is:" & $RandomNum) If MsgBox(1, "", "continue?") = 2 Then Exit Else ExitLoop EndIf Else Select Case $Guess > $setMax Or $Guess < $setMin MsgBox(0, "", "Must be in the Range of" & @CRLF & $setMin & " and " & $setMax) Case $Guess < $RandomNum If $Guess > $GuessMin Then $GuessMin = $Guess EndIf MsgBox(0, "", "Too low..." & @CRLF & $GuessMin & "-" & $GuessMax) Case $Guess > $RandomNum If $Guess < $GuessMax Then $GuessMax = $Guess EndIf MsgBox(0, "", "Too high..." & @CRLF & $GuessMin & "-" & $GuessMax) EndSelect EndIf EndIf WEnd WEnd Now we reset the limits with each incorrect guess. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Developers Jos Posted March 2, 2013 Developers Share Posted March 2, 2013 Avoiding who set wrong number out of range..... but you are overriding the original range (Min and Max) and loose your original values. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Underdogger Posted March 2, 2013 Author Share Posted March 2, 2013 Underdogger, Understood - so this should do the trick: While 1 Local $setMax = InputBox("", "Input Max Num:") Local $setMin = InputBox("", "Input Min Num:") Local $GuessMax = $setMax Local $GuessMin = $setMin $RandomNum = Random($setMin, $setMax, 1) While 1 $Guess = InputBox("", "Guess Number:") If @error <> 1 Then If $Guess = $RandomNum Then MsgBox(0, "", "Excellent!" & @CRLF & "The Number is:" & $RandomNum) If MsgBox(1, "", "continue?") = 2 Then Exit Else ExitLoop EndIf Else Select Case $Guess > $setMax Or $Guess < $setMin MsgBox(0, "", "Must be in the Range of" & @CRLF & $setMin & " and " & $setMax) Case $Guess < $RandomNum If $Guess > $GuessMin Then $GuessMin = $Guess EndIf MsgBox(0, "", "Too low..." & @CRLF & $GuessMin & "-" & $GuessMax) Case $Guess > $RandomNum If $Guess < $GuessMax Then $GuessMax = $Guess EndIf MsgBox(0, "", "Too high..." & @CRLF & $GuessMin & "-" & $GuessMax) EndSelect EndIf EndIf WEnd WEnd Now we reset the limits with each incorrect guess. M23 Sorry for my bad expression to let you misunderstand.. It works pretty... Link to comment Share on other sites More sharing options...
Underdogger Posted March 2, 2013 Author Share Posted March 2, 2013 .. but you are overriding the original range (Min and Max) and loose your original values.Sorry for my bad expression...Melba's version is running pretty! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now