Question: I have been working on this Code for a week now and I can not figure out why it is not working. Any help at
I have been working on this Code for a week now and I can not figure out why it is not working. Any help at all would be greatly appreciated because I am lost/stuck on what is wrong.
************************************************************************* 'Script Name: GuessANumber.vbs 'Author: ---- '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 intNoGuesses = 0 'Main Processing Section '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" Exit Do '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 '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 & vbCrLf & "You guessed it " & _ "in " & intNoGuesses & " guesses.", , cGreetingMsg strOkToEnd = "yes" Exit Do 'Test to see if the user's guess was too low If FormatNumber(intUserNumber) < intRandomNo Then MsgBox "Your guess was too low. 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(intRandomNo-FormatNumber(intUserNumber))> 80 Then MsgBox "Your guess 80 numbers too low. Try again.", , cGreetingMsg ElseIf FormatNumber(intUserNumber) < intRandomNo Then If(intRandomNo-FormatNumber(intUserNumber))> 60 Then MsgBox "Your guess 60 numbers too low. Try again.", , cGreetingMsg ElseIf FormatNumber(intUserNumber) < intRandomNo Then ElseIf(intRandomNo-FormatNumber(intUserNumber))> 40 Then MsgBox "Your guess 40 numbers too low. Try again", , cGreetingMsg ElseIf FormatNumber(intUserNumber) < intRandomNo Then ElseIf (intRandomNo-FormatNumber(intUserNumber))> 20 Then MsgBox "Your guess 20 numbers too low. Try again", , cGreetingMsg ElseIf FormatNumber(intUserNumber) < intRandomNo Then ElseIf (intRandomNo-FormatNumber(intUserNumber))> 10 Then MsgBox "Your guess 10 numbers too low. Try again", , cGreetingMsg strOkToEnd = "no" 'Test to see if the user's guess was 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 high If FormatNumber(intUserNumber) > intRandomNo Then If(intRandomNo-FormatNumber(intUserNumber)) > 80 Then MsgBox "Your guess 80 numbers too high. Try again", , cGreetingMsg ElseIf FormatNumber(intUserNumber) > intRandomNo Then ElseIf (intRandomNo-FormatNumber(intUserNumber)) > 60 Then MsgBox "Your guess 60 numbers too high. Try again", , cGreetingMsg ElseIf FormatNumber(intUserNumber) > intRandomNo Then ElseIf (intRandomNo-FormatNumber(intUserNumber)) > 40 Then MsgBox "Your guess 40 numbers too high. Try again", , cGreetingMsg ElseIf FormatNumber(intUserNumber) > intRandomNo Then ElseIf (intRandomNo-FormatNumber(intUserNumber)) > 20 Then MsgBox "Your guess 20 numbers too high. Try again", , cGreetingMsg ElseIf FormatNumber(intUserNumber) > intRandomNo Then ElseIf (intRandomNo-FormatNumber(intUserNumber)) > 10 Then MsgBox "Your guess 10 numbers too high. Try again", , cGreetingMsg strOkToEnd = "no" End If Else MsgBox "Sorry. You did not enter a number. Try again.", cGreetingMsg End If Else MsgBox "You either failed to type a value or you clicked on Cancel. " & _ "Please play again soon!" , , cGreetingMsg strOkToEnd = "yes" Exit Do End If Loop End
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
