Option Explicit Sub HighOrLow() Dim name As String Dim balance As Long Dim Cards Dim Bet Dim HiLo As String name = InputBox("Please enter your name:") MsgBox ("Hi " & name & " Welcome to High and Low game") balance = 100 If name = vbNullString Then Exit Sub Cards = Array("Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King") Call GetBet((name), (balance)) Call GetHighOrLow((name), (balance), (Bet), (Cards)) End Sub Function GetBet(name As String, balance As Long) Dim Bet As Integer Bet = InputBox(name & ", your current balance is $" & balance & "." & vbNewLine & "How much do you want to bet?") MsgBox ("So you want to bet: " & Bet & "$") If Bet = False Then Exit Function If Bet <> Int(Bet) Or Bet < 1 Or Bet > balance Then MsgBox (name & ", you must enter a whole number between 1 and " & balance & ".") Call GetBet(name, balance) End If End Function Function GetHighOrLow(name As String, balance As Long, Bet As Integer, Cards) Dim HiLo As String Dim ComCard As String Dim RanCard(1 To 2) As Integer Dim H, L As String Randomize RanCard(1) = Int(13 * Rnd + 1) RanCard(2) = Int(13 * Rnd + 1) HiLo = InputBox(name & ", your card is: " & RanCard(1) & vbNewLine & "Do you think the computer's card is higher [H] or lower [L]?") If Not UCase(HiLo) Like "[HL]" Then MsgBox (name & ", you must enter [H] for higher or [L] for lower.") Call GetHighOrLow(name, balance, Bet, Cards) End If If HiLo = vbNullString Then Exit Function ComCard = (vbNewLine & "The computer's card is: " & Application.Index(Cards, RanCard(2))) Do While HiLo = H If RanCard(2) > RanCard(1) Then MsgBox ("That's correct, " & name & "." & ComCard & vbNewLine & "your balance: " & balance = balance + Bet) ElseIf RanCard(2) < RanCard(1) Then MsgBox ("That's incorrect, " & name & "." & ComCard & vbNewLine & "Your balance: " & balance = balance - Bet) Else MsgBox ("It's a tie, " & name & "." & vbNewLine & ComCard & vbNewLine & "Your balance: " & balance) End If Do While HiLo = L If RanCard(2) < RanCard(1) Then MsgBox ("That's correct, " & name & "." & ComCard & "Your balance" & balance = balance + Bet) ElseIf RanCard(2) > RanCard(1) Then MsgBox ("That's incorrect, " & name & "." & ComCard & "Your balance" & balance = balance - Bet) Else MsgBox ("It's a tie, " & name & "." & ComCard & "Your balance" & balance) End If Loop Loop If balance > 0 Then Call GetBet(name, balance) Else MsgBox (name & ", your balance is $0." & "Thanks for playing this game" & " see ya") End If End Function