Jump to content

Guess Number


Recommended Posts

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 by Underdogger
Link to comment
Share on other sites

  • Moderators

Underdogger,

What does it not do that you think it should? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Underdogger,

What does it not do that you think it should? :huh:

M23

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 ?

My 1st ver. it can run normally..

but while I added two inputboxs on top, It got error..

Edited by Underdogger
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Developers

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

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 by Underdogger
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Developers

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...