Jump to content

Need help with closing Inputbox?


Recommended Posts

I made this program based off pseudocode I have been learning in a class. I decided to pick up auto it just for practice. Now I run into a problem.. When you click the x in the top right corner it just gives the incorrect answer response.. All I want it to do is exit if the user hits the x. Also I know there has to be an easier way to 'print' the array list rather than doing it the way I used.. as in array[0] & array[1] etc..

#include <Array.au3>

Global $symbol = " x "
Dim $quizType[4]
$quizType[0] = "1) Addition Quiz                                                                 "
$quizType[1] = "2) Multiplication Quiz                                                         "
$quizType[2] = "3) Subtraction Quiz                                                          "
$quizType[3] = "4) Division Quiz                                                                 " 
$quizTypeHeading = "Select Quiz Type"



mainloop()


func mainloop()
$menuSwitch = 0
while $menuSwitch < 1
$selectType = InputBox ( $quizTypeHeading, $quizType[0] & $quizType[1] & $quizType[2] & $quizType[3], "Please Select a Quiz. 1 - 4","",300,250)
Select
case $selectType = 1 
    addQuiz()
$menuSwitch = $menuSwitch + 1   
Case $selectType = 2
    multQuiz()
    $menuSwitch = $menuSwitch + 1   
case $selectType = 3
    subQuiz()
    $menuSwitch = $menuSwitch + 1   
case $selectType = 4
    divQuiz()
    $menuSwitch = $menuSwitch + 1   
Case Else
    MsgBox (1, "Invalid Selection", "Please select a quiz using the numbers 1 through 4")
EndSelect
WEnd
Return
EndFunc

func addQuiz()
$count = 0
$firstNumber = 1
$secondNumber = 1
while $count < 3
    $solution = $firstNumber + $secondNumber
    $symbol = " + "
    $add = InputBox ( $quiztype[0] , $firstNumber & $symbol & $secondNumber & ' = ?', "Answer")
    if $add = $solution then
      MsgBox (1, "Congradulations!", "Thats Right! " & $firstNumber & $symbol & $secondNumber & " = " &  $solution)
      $count = 0
      $secondNumber = $secondNumber + 1
      if $secondNumber >= 11 Then
          $firstNumber = $firstNumber + 1
          $secondNumber = 1
      EndIf
      if $firstnumber >= 11 Then
          MsgBox (1, "ALL DONE!!!", "Way to Go!! You Pass!!")
          Exit
          EndIf
    else
      $count = $count + 1
      if $count = 3 Then
          MsgBox (1, "Exceeded number of tries", "The correct answer was " & $firstNumber & $symbol & $secondNumber & " = " & $solution)
          $count = 0
      Else
          MsgBox (1, "Incorrect Answer", "Please Try Again")          
  EndIf
  EndIf
  WEnd
EndFunc

func multQuiz()
    $count = 0
$firstNumber = 1
$secondNumber = 1
while $count < 3
    $solution = $firstNumber * $secondNumber
    $symbol = " x "
    $add = InputBox ($quizType[1], $firstNumber & $symbol & $secondNumber & ' = ?', "Answer")
    if $add = $solution then
      MsgBox (1, "Congradulations!", "Thats Right! " & $firstNumber & $symbol & $secondNumber & " = " &  $solution)
      $count = 0
      $secondNumber = $secondNumber + 1
      if $secondNumber >= 11 Then
          $firstNumber = $firstNumber + 1
          $secondNumber = 1
      EndIf
      if $firstnumber >= 11 Then
          MsgBox (1, "ALL DONE!!!", "Way to Go!! You Pass!!")
          Exit
          EndIf
    else
      $count = $count + 1
      if $count = 3 Then
          MsgBox (1, "Exceeded number of tries", "The correct answer was " & $firstNumber & $symbol & $secondNumber & " = " & $solution)
          $count = 0
      Else
          MsgBox (1, "Incorrect Answer", "Please Try Again")          
  EndIf
  EndIf
  WEnd
  EndFunc
  
  func subQuiz()
      $count = 0
$firstNumber = 1
$secondNumber = 1
while $count < 3
    $solution = $secondNumber - $firstNumber
    $symbol = " - "
    $add = InputBox ($quizType[2], $secondNumber & $symbol & $firstNumber & ' = ?', "Answer")
    if $add = $solution then
      MsgBox (1, "Congradulations!", "Thats Right! " & $secondNumber & $symbol & $firstNumber & " = " &  $solution)
      $count = 0
      $secondNumber = $secondNumber + 1
      if $secondNumber >= 11 Then
          $firstNumber = $firstNumber + 1
          $secondNumber = 1
      EndIf
      if $firstnumber >= 11 Then
          MsgBox (1, "ALL DONE!!!", "Way to Go!! You Pass!!")
          Exit
          EndIf
    else
      $count = $count + 1
      if $count = 3 Then
          MsgBox (1, "Exceeded number of tries", "The correct answer was " & $secondNumber & $symbol & $firstNumber & " = " & $solution)
          $count = 0
      Else
          MsgBox (1, "Incorrect Answer", "Please Try Again")          
  EndIf
  EndIf
  WEnd
  EndFunc
  
  func divQuiz()
      $count = 0
$firstNumber = 1
$secondNumber = 1
while $count < 3
    $solution = $secondNumber / $firstNumber
    $symbol = " / "
    $add = InputBox ($quizType[3], $secondNumber & $symbol & $firstNumber & ' = ?', "Answer")
    if $add = $solution then
      MsgBox (1, "Congradulations!", "Thats Right! " & $secondNumber & $symbol & $firstNumber & " = " &  $solution)
      $count = 0
      $secondNumber = $secondNumber + 1
      if $secondNumber >= 11 Then
          $firstNumber = $firstNumber + 1
          $secondNumber = 1
      EndIf
      if $firstnumber >= 11 Then
          MsgBox (1, "ALL DONE!!!", "Way to Go!! You Pass!!")
          Exit
          EndIf
    else
      $count = $count + 1
      if $count = 3 Then
          MsgBox (1, "Exceeded number of tries", "The correct answer was " & $secondNumber & $symbol & $firstNumber & " = " & $solution)
          $count = 0
      Else
          MsgBox (1, "Incorrect Answer", "Please Try Again")          
  EndIf
  EndIf
  WEnd
EndFunc
Edited by TokeySmurf
Link to comment
Share on other sites

Maybe...

#include <Array.au3>
Global $symbol = " x "
Dim $quizType[4]
$quizType[0] = "1) Addition Quiz                                                                 "
$quizType[1] = "2) Multiplication Quiz                                                           "
$quizType[2] = "3) Subtraction Quiz                                                             "
$quizType[3] = "4) Division Quiz                                                                 "
$quizTypeHeading = "Select Quiz Type"
mainloop()
Func mainloop()
    $menuSwitch = 0
    While $menuSwitch < 1
        $selectType = InputBox($quizTypeHeading, $quizType[0] & $quizType[1] & $quizType[2] & $quizType[3], "Please Select a Quiz. 1 - 4", "", 300, 250)
        If @error = 1 Then Exit
        Select
            Case $selectType = 1
                addQuiz()
                $menuSwitch = $menuSwitch + 1
            Case $selectType = 2
                multQuiz()
                $menuSwitch = $menuSwitch + 1
            Case $selectType = 3
                subQuiz ()
                $menuSwitch = $menuSwitch + 1
            Case $selectType = 4
                divQuiz ()
                $menuSwitch = $menuSwitch + 1
            Case Else
                If MsgBox(1, "Invalid Selection", "Please select a quiz using the numbers 1 through 4") <> 1 Then Exit
        EndSelect
    WEnd
    Return
EndFunc   ;==>mainloop
Func addQuiz()
    $count = 0
    $firstNumber = 1
    $secondNumber = 1
    While $count < 3
        $solution = $firstNumber + $secondNumber
        $symbol = " + "
        $add = InputBox($quizType[0], $firstNumber & $symbol & $secondNumber & ' = ?', "Answer")
        If @error = 1 Then Exit
        If $add = $solution Then
            MsgBox(1, "Congradulations!", "Thats Right! " & $firstNumber & $symbol & $secondNumber & " = " & $solution)
            $count = 0
            $secondNumber = $secondNumber + 1
            If $secondNumber >= 11 Then
                $firstNumber = $firstNumber + 1
                $secondNumber = 1
            EndIf
            If $firstNumber >= 11 Then
                MsgBox(1, "ALL DONE!!!", "Way to Go!! You Pass!!")
                Exit
            EndIf
        Else
            $count = $count + 1
            If $count = 3 Then
                If MsgBox(1, "Exceeded number of tries", "The correct answer was " & $firstNumber & $symbol & $secondNumber & " = " & $solution) <> 1 Then Exit
                $count = 0
            Else
                If MsgBox(1, "Incorrect Answer", "Please Try Again") <> 1 Then Exit
            EndIf
        EndIf
    WEnd
EndFunc   ;==>addQuiz
Func multQuiz()
    $count = 0
    $firstNumber = 1
    $secondNumber = 1
    While $count < 3
        $solution = $firstNumber * $secondNumber
        $symbol = " x "
        $add = InputBox($quizType[1], $firstNumber & $symbol & $secondNumber & ' = ?', "Answer")
        If @error = 1 Then Exit
        If $add = $solution Then
            If MsgBox(1, "Congradulations!", "Thats Right! " & $firstNumber & $symbol & $secondNumber & " = " & $solution) <> 1 Then Exit
            $count = 0
            $secondNumber = $secondNumber + 1
            If $secondNumber >= 11 Then
                $firstNumber = $firstNumber + 1
                $secondNumber = 1
            EndIf
            If $firstNumber >= 11 Then
                MsgBox(1, "ALL DONE!!!", "Way to Go!! You Pass!!")
                Exit
            EndIf
        Else
            $count = $count + 1
            If $count = 3 Then
                If MsgBox(1, "Exceeded number of tries", "The correct answer was " & $firstNumber & $symbol & $secondNumber & " = " & $solution) <> 1 Then Exit
                $count = 0
            Else
                If MsgBox(1, "Incorrect Answer", "Please Try Again") <> 1 Then Exit
            EndIf
        EndIf
    WEnd
EndFunc   ;==>multQuiz
Func subQuiz ()
    $count = 0
    $firstNumber = 1
    $secondNumber = 1
    While $count < 3
        $solution = $secondNumber - $firstNumber
        $symbol = " - "
        $add = InputBox($quizType[2], $secondNumber & $symbol & $firstNumber & ' = ?', "Answer")
        If @error = 1 Then Exit
        If $add = $solution Then
            If MsgBox(1, "Congradulations!", "Thats Right! " & $secondNumber & $symbol & $firstNumber & " = " & $solution) <> 1 Then Exit
            $count = 0
            $secondNumber = $secondNumber + 1
            If $secondNumber >= 11 Then
                $firstNumber = $firstNumber + 1
                $secondNumber = 1
            EndIf
            If $firstNumber >= 11 Then
                MsgBox(1, "ALL DONE!!!", "Way to Go!! You Pass!!")
                Exit
            EndIf
        Else
            $count = $count + 1
            If $count = 3 Then
                If MsgBox(1, "Exceeded number of tries", "The correct answer was " & $secondNumber & $symbol & $firstNumber & " = " & $solution) <> 1 Then Exit
                $count = 0
            Else
                If MsgBox(1, "Incorrect Answer", "Please Try Again") <> 1 Then Exit
            EndIf
        EndIf
    WEnd
EndFunc   ;==>subQuiz
Func divQuiz ()
    $count = 0
    $firstNumber = 1
    $secondNumber = 1
    While $count < 3
        $solution = $secondNumber / $firstNumber
        $symbol = " / "
        $add = InputBox($quizType[3], $secondNumber & $symbol & $firstNumber & ' = ?', "Answer")
        If @error = 1 Then Exit
        If $add = $solution Then
            If MsgBox(1, "Congradulations!", "Thats Right! " & $secondNumber & $symbol & $firstNumber & " = " & $solution) <> 1 Then Exit
            $count = 0
            $secondNumber = $secondNumber + 1
            If $secondNumber >= 11 Then
                $firstNumber = $firstNumber + 1
                $secondNumber = 1
            EndIf
            If $firstNumber >= 11 Then
                MsgBox(1, "ALL DONE!!!", "Way to Go!! You Pass!!")
                Exit
            EndIf
        Else
            $count = $count + 1
            If $count = 3 Then
                If MsgBox(1, "Exceeded number of tries", "The correct answer was " & $secondNumber & $symbol & $firstNumber & " = " & $solution) <> 1 Then Exit
                $count = 0
            Else
                If MsgBox(1, "Incorrect Answer", "Please Try Again") <> 1 Then Exit
            EndIf
        EndIf
    WEnd
EndFunc   ;==>divQuiz

8)

NEWHeader1.png

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...