Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello I am trying to test the functions for the high and low values any sort of

ID: 3835047 • Letter: H

Question

Hello I am trying to test the functions for the high and low values
any sort of help would be greatly appreciated

'*************************************************************************
'Script Name: GuessANumber.vbs
'Author: Rance Perrino
'Created: 04/20/2017
'Description: This script plays a number-guessing game with the user
'*************************************************************************

'Initialization Section

Option Explicit

Const cGreetingMsg = "Pick a number between 1 - 100"

Dim intUserNumber, intRandomNo, strOkToEnd, intNoGuesses, intRange, strBadData, name
name=inputbox("Hello. What is your name?!")
msgbox ("Greetings:" & name)

strOkToEnd = "no"
intNoGuesses = 0

'Main Processing Section

'Generate a random number
RandomNumber()
intRandomNo = FormatNumber(Int((100 * Rnd) + 1))

strOkToEnd = "no"

'Procedure Section

'Generate the game's random number

'Generate a random number
Randomize
intRandomNo = FormatNumber(Int((100 * Rnd) + 1))

'Loop until either the user guesses correctly or the user clicks on Cancel
Do Until strOkToEnd = "yes"

'Prompt users to pick a number
intUserNumber = InputBox("Type your guess:",cGreetingMsg)
intNoGuesses = intNoGuesses + 1

'See if the user provided an answer
   If Len(intUserNumber) <> 0 Then

           'Make sure that the player typed a number
           If IsNumeric(intUserNumber) = "True" Then
          
              'Determine if the player's guess is too low, too high, or just right
              
                   'Test to see if the user's guess was correct
               If FormatNumber(intUserNumber) = intRandomNo Then
                   MsgBox "Congratulations! You guessed it. The number was " &_
                   intUserNumber & "." & vbCrLf & "You guessed it " & _
                   "in " & intNoGuesses & " guesses.", ,cGreetingMsg
                   strOkToEnd = "yes"
               End If

               'Test to see if the user's guess was too low
              
               Function Is Too Low()
               If FormatNumber(intUserNumber) < intRandomNo Then
                  MsgBox "Your guess was too low. Try again", , cGreetingMsg
                  strOkToEnd = "no"
               End If

               'Test to see if the user's guess was too high
              
               Function Is Too High()
               If FormatNumber(intUserNumber) > intRandomNo Then
                  MsgBox "Your guess was too high. Try again", , cGreetingMsg
                  strOkToEnd = "no"
               End If
  
'80,60,40,20,10 or farther from the correct guess, but still too low

               If FormatNumber(intUserNumber) < intRandomNo Then
                   If FormatNumber(intRandomNo - FormatNumber(intUserNumber)) > 80 Then
                       MsgBox "Your guess 80 numbers too low. Try again.", , cGreetingMsg
      
                       ElseIf FormatNumber(intRandomNo - FormatNumber(intUserNumber)) > 60 Then
                       MsgBox "Your guess 60 numbers too low. Try again.", , cGreetingMsg
  
                       ElseIf FormatNumber(intRandomNo - FormatNumber(intUserNumber)) > 40 Then
                       MsgBox "Your guess 40 numbers too low. Try again", , cGreetingMsg
  
                       ElseIf FormatNumber(intRandomNo - FormatNumber(intUserNumber)) > 20 Then
                       MsgBox "Your guess 20 numbers too low. Try again", , cGreetingMsg
  
                       ElseIf (intRandomNo - FormatNumber(intUserNumber)) > 10 Then
                       MsgBox "Your guess 10 numbers too low. Try again", , cGreetingMsg
      
               End Function
              
               End If
     
'Test to see if the user's guess was too high
ElseIf (intUserNumber > intRandomNo) Then
     
'80,60,40,20,10 or farther from the correct guess, but still too high
     
               If(intRandomNo - FormatNumber(intUserNumber)) > 80 Then
                   MsgBox "Your guess was 80 numbers too high. Try again", , cGreetingMsg
  
                   ElseIf (intUserNumber - FormatNumber(intRandomNo)) < 60 Then
                   MsgBox "Your guess 60 numbers too high. Try again", , cGreetingMsg
  
                   ElseIf (intUserNumber - FormatNumber(intRandomNo)) < 40 Then
                   MsgBox "Your guess 40 numbers too high. Try again", , cGreetingMsg
  
                   ElseIf (intUserNumber - FormatNumber(intRandomNo)) < 20 Then
                   MsgBox "Your guess 20 numbers too high. Try again", , cGreetingMsg

                   ElseIf (intUserNumber - FormatNumber(intRandomNo)) < 10 Then
                   MsgBox "Your guess 10 numbers too high. Try again", , cGreetingMsg
  
           End If  
  
               strOkToEnd = "no"
  
               End If
  
   Else
               MsgBox "Sorry. You did not enter a number. Try again.", cGreetingMsg
  
   End If

Loop

Explanation / Answer

CODE:-


'Script Name: GuessANumber.vbs

'Author: ----

'Created: 04/20/2017

'Description: This script plays a number-guessing game with the user

initialization section ' initializing the section'

Option Explicit
'guess any no.in between the given range'

Const cGreetingMsg = "Pick a number between 1 - 100"
' Variables are declared'

Dim intUserNumber, intRandomNo, strOkToEnd, intNoGuesses, intRange

intNoGuesses = 0 'guessed no. is initially set to zero'

'This is the main process section'

'A random number is generated'

Randomize

intRandomNo = Int((100 * Rnd) + 1) 'random no. defined'

strOkToEnd="no" ' set to no'

'the Loop runs until the user guess is correct or the user shooses to cancel'

Do Until strOkToEnd = "yes" 'set to yes'

'user is asked to pick a number'

intUserNumber = InputBox("Type your guess:",cGreetingMsg)'user enter the number'

intNoGuesses = intNoGuesses + 1 ' the guessed no. is incremented by 1'

'check if there is an answer by the user'

If Len(intUserNumber) <> 0 Then ' if conditional statement for other case'

'make sure player should must type a no'

If IsNumeric(intUserNumber) = "True" Then 'if the user number is true'

'now, check if the users guess is correct'

If intUserNumber = intRandomNo Then 'if the user no. is equal to the random number'
' message delivered to the user'
MsgBox "Congratulations! You guessed it. The number was " & _
' user number is being entered and is guessed'
intUserNumber & "." & vbCrLf & vbCrLf & "You guessed it " & _

"in " & intNoGuesses & " guesses.", , cGreetingMsg 'guessing number'

strOkToEnd = "yes" 'OkToEnd shows yes'   

End If ' end of the statement'

'80,60,40,20,10 from the correct guess, but still too low'

If intUserNumber < intRandomNo Then 'if the user no. is less than the random no.'

If(intRandomNo-intUserNumber)> 80 Then 'if the difference ofrandom no. and user no is greater than 80'

MsgBox "Your guess 80 numbers too low. Try again.", , cGreetingMsg 'message to the user'

ElseIf(intRandomNo-intUserNumber)> 60 Then 'if the difference ofrandom no. and user no is greater than 60'

MsgBox "Your guess 60 numbers too low. Try again.", , cGreetingMsg 'message to the user'

ElseIf(intRandomNo-intUserNumber)> 40 Then 'if the difference ofrandom no. and user no is greater than 40'

MsgBox "Your guess 40 numbers too low. Try again", , cGreetingMsg ' message to the user'

ElseIf (intRandomNo-intUserNumber)> 20 Then 'if the difference ofrandom no. and user no is greater than 80'

MsgBox "Your guess 20 numbers too low. Try again", , cGreetingMsg 'message to the user'

ElseIf (intRandomNo-intUserNumber)> 10 Then 'if the difference ofrandom no. and user no is greater than 10'

MsgBox "Your guess 10 numbers too low. Try again", , cGreetingMsg' message to the user'

End If ' end of the statement'

strOkToEnd = "no" 'OkToEnd is negative'   

'Check if the user have a higher guess'

ElseIf intUserNumber > intRandomNo Then' if the user no. is greater than the ramdom number'

'80,60,40,20,10 from the correct guess, but still too high'

If(intUserNumber- intRandomNo) > 80 Then 'if the difference ofrandom no. and user no is greater than 80'

MsgBox "Your guess 80 numbers too high. Try again", , cGreetingMsg 'message to the user'

ElseIf (intUserNumber- intRandomNo) > 60 Then 'if the difference ofrandom no. and user no is greater than 60'

MsgBox "Your guess 60 numbers too high. Try again", , cGreetingMsg 'message to the user'

ElseIf (intUserNumber- intRandomNo) > 40 Then 'if the difference ofrandom no. and user no is greater than 40'

MsgBox "Your guess 40 numbers too high. Try again", , cGreetingMsg 'message to the user'

ElseIf (intUserNumber- intRandomNo) > 20 Then 'if the difference ofrandom no. and user no is greater than 20'

MsgBox "Your guess 20 numbers too high. Try again", , cGreetingMsg 'message to the user'

ElseIf (intUserNumber- intRandomNo) > 10 Then'if the difference ofrandom no. and user no is greater than 10'

MsgBox "Your guess 10 numbers too high. Try again", , cGreetingMsg 'message to the user'

End If 'end of the statement'

strOkToEnd = "no" ' again OkToEnd is negative'   

End If'end of the statement'

End If'end of the statement'

Else ' in case if the user does not provide any input'

MsgBox "Sorry. You did not enter a number. Try again.", cGreetingMsg 'message to the user'

End If 'end of the statement'

Loop

End 'end of the loop'

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote