I need the code of craps game Visual Basic I need the code o
Solution
Solution: See the code below:
--------------------------------------------------------
Module VBModule
\'function to roll dices
Function RollDice() As Integer
Dim sum As Integer
Dim dice1 As Integer
Dim dice2 As Integer
dice1=1 + Int(Rnd(1) * 6)
dice2=1 + Int(Rnd(1) * 6)
sum=dice1+dice2
RollDice=sum
End Function
\'function to play one game of craps
Function PlayOneGame() As Integer
Dim dicetotal As Integer
dicetotal=RollDice()
Console.WriteLine(\"You rolled \" & dicetotal.ToString())
Dim result As Integer
If dicetotal = 7 Or dicetotal = 11 Then
result = 1
ElseIf dicetotal = 2 Or dicetotal = 3 Or dicetotal = 12 Then
result = 0
ElseIf dicetotal = 4 Or dicetotal = 5 Or dicetotal = 6 Or dicetotal = 8 Or dicetotal = 9 Or dicetotal = 10 Then
result = dicetotal
End If
PlayOneGame = result
End Function
\'play craps game
Sub Craps()
Console.WriteLine(\"Welcome to CRAPS game\")
Dim bankbalance As Double
bankbalance=1000 \'initial bank balance
Console.WriteLine(\"Your initial bank balance is \" & bankbalance.ToString())
While bankbalance <> 0
Dim wager As Double
Console.Write(\"Enter your wager:\")
Dim input=Console.ReadLine()
wager=Convert.ToDouble(input)
If wager <= bankbalance Then
Console.WriteLine(\"Ok, lets play\")
Else
Console.Write(\"Cannot wager more than \" & bankbalance.ToString() & \"Re-enter:\")
input=Console.ReadLine()
wager=Convert.ToDouble(input)
End If
Dim result As Integer
result = PlayOneGame()
If result = 1 Then
Console.WriteLine(\"You win!\")
bankbalance = bankbalance + wager
Console.WriteLine(\"Your new bank balance is \" & bankbalance.ToString())
ElseIf result = 0 Then
Console.WriteLine(\"You loose!\")
bankbalance = bankbalance - wager
Console.WriteLine(\"Your new bank balance is \" & bankbalance.ToString())
Else
Console.WriteLine(\"You point is \" & result.ToString())
While 1
Dim sum As Integer
Dim dice1 As Integer
Dim dice2 As Integer
dice1=1 + Int(Rnd(1) * 6)
dice2=1 + Int(Rnd(1) * 6)
sum=dice1+dice2
If sum = result Then
Console.WriteLine(\"You win!\")
bankbalance = bankbalance + wager
Console.WriteLine(\"Your new bank balance is \" & bankbalance.ToString())
Exit While
ElseIf sum = 7 Then
Console.WriteLine(\"You loose!\")
bankbalance = bankbalance - wager
Console.WriteLine(\"Your new bank balance is \" & bankbalance.ToString())
Exit While
End If
If bankbalance = 0 Then
Console.WriteLine(\"Sorry, you are broken!\")
Exit While
Else
Dim choice As Char
Console.Write(\"Do you want to play again (y/n):\")
input=Console.Read()
If choice = \"n\" Then
If bankBalance > 0 Then
If bankBalance > 1000 Then
Dim profit As Double
profit = bankBalance - 1000
Console.WriteLine(\"Congratulations! you made $\" & profit.ToString())
Else
Dim loss as Double
loss = 1000 - bankBalance
Console.WriteLine(\"Bad luck! you lost $\" & loss.ToString())
End If
End If
Exit While
End If
End If
End While
End If
End While
End Sub
\'main procedure
Sub Main()
\'play game of craps
craps()
End Sub
End Module
-------------------------------------------

