Hello friends,
I have written one code where you select either ball,bat or stump instead of that it gives you only one winner (Computer wins),but in my code it just displays all the Message boxes.I don't know where i have made mistake.
Code:
'Formally declare variables used by the script before trying to use them
Dim WshShl, Answer, CardImage
'Create an instance of the WScript object in order to later use the
'Popup method
Set WshShl = WScript.CreateObject("WScript.Shell")
'Display the rules of the game
WshShl.Popup "Welcome to ball, bat and stump game. Here are the " & _
"rules of the game: 1. Guess the same thing as the computer " & _
"to tie. 2. Bat covers Ball and wins. 3. Ball breaks " & _
"stump and wins. 4. Stump hit bat and wins."
'Prompt the user to select a choice
Answer = InputBox("Type Ball, Bat and Stump.", _
"Let's play a game!")
'Time for the computer to randomly pick a choice
Randomize
GetRandomNumber = Round(FormatNumber(Int((3 * Rnd()) + 1)))
'Assign a value to the randomly selected number
If GetRandomNumber = 3 then CardImage = "Ball"
If GetRandomNumber = 2 then CardImage = "Bat"
If GetRandomNumber = 1 then CardImage = "Stump"
'Display the game's results so that the user can see if he or she won
WshShl.Popup "You picked: " & Answer & Space(12) & "Computer picked: " & _
CardImage
If Answer = "ball" & CardImage <> "bat" then _
MsgBox "Bat Covers Ball:Computer wins!"
If Answer = "bat" & CardImage <> "Stump" then MsgBox "Stump Cuts bat:Computer wins!"
If Answer = "stump" & CardImage <> "ball" then MsgBox "Ball Breaks Stump:Computer wins!"
If CardImage = "ball" & Answer <> "bat" then MsgBox "Bat Covers ball:You wins!"
If CardImage = "bat" & Answer<> "Stump" then MsgBox "Stump Cuts Bat:You wins!"
If CardImage = "stump" & Answer <> "ball" then MsgBox "Ball Breaks Stump:You wins!"
If CardImage = "bat" & Answer <> "bat" then MsgBox "TIE!"
If CardImage = "stump" & Answer<> "stump" then MsgBox "TIE!"
If CardImage = "ball" & Answer <> "ball" then MsgBox "TIE!"
Bookmarks