vb programming issue i am creating a dice game (craps), once the dice is rolled
ID: 3698352 • Letter: V
Question
vb programming issue
i am creating a dice game (craps), once the dice is rolled the sum will result in one of 3 cases (win, lose, or point). a sum = 7 or 11 they win, a sum = 2, 3, or 12 they lose, and any other sum = the point. my problem is with the third case (point). when the sum = 4, 5, 6, 8, 9, or 10 it results in a point = to that sum. the player then has to roll again and keeps rolling until the sum = the point or they roll a 7. if the sum = the point they win, sum = 7 and they lose. the problem occurs when my code reaches the Do/Loop statement. the form is saving the point but continues to follow the same rules prior to rolling a point (a sum = 7 or 11 they win, a sum = 2, 3, or 12 they lose, and any other sum = the point) instead of the new rules when having a point (sum = the point they win, sum = 7 and they lose). Here is my code:
'determine and display if player wins, loses, or rolls a point
If DiceTotalInteger = 7 Or DiceTotalInteger = 11 Then
BankInteger = (BetInteger * 2) + BankInteger
LabelBank.Text = BankInteger.ToString("c")
BetInteger = 0
LabelBet.Text = BetInteger
MessageBox.Show("You Win!")
ElseIf DiceTotalInteger = 2 Or DiceTotalInteger = 3 Or DiceTotalInteger = 12 Then
BetInteger = 0
LabelBet.Text = BetInteger
MessageBox.Show("You Lose!")
Else
PointInteger = DiceTotalInteger
LabelPoint.Text = PointInteger
MessageBox.Show("You Rolled A Point, Continue Rolling To Win Or Lose")
Do Until DiceTotalInteger = PointInteger Or DiceTotalInteger = 7
If DiceTotalInteger = 7 Then
BetInteger = 0
LabelBet.Text = BetInteger.ToString("c")
LabelBank.Text = BankInteger
MessageBox.Show("You Lose!")
ElseIf DiceTotalInteger = PointInteger Then
BankInteger = (BetInteger * 2) + BankInteger
LabelBank.Text = BankInteger
BetInteger = 0
MessageBox.Show("You Win!")
End If
Loop
End If
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main ()
{
int i,d1,d2,sumd,sumd2;
double winf = 0, lostf = 0, winp = 0, lostp = 0;
printf("This program will simulate the game of craps for 100 times. ");
for (i=0; i<100; i++) {
d1 = rand()%6+1;
d2 = rand()%6+1;
sumd = d1 + d2;
if (sumd==7 || sumd==11) {
printf("You rolled a 7 or an 11, you win. ");
winf++;
}
if (sumd==2 || sumd==3 || sumd==12) {
printf("You rolled a 12, a 3, or a 2, you lose. ");
lostf++;
}
if (sumd==4 || sumd==5 || sumd==6 || sumd==8 || sumd==9 || sumd==10) {
while (1) {
d1 = rand()%6+1;
d2 = rand()%6+1;
sumd2 = d1 + d2;
if (sumd2==sumd){
printf("You rolled your points, you win. ");
winp++;
break;}
if (sumd==7){
printf("You rolled a 7, you lose. ");
lostp++;
break;}
}
}
}
printf("First roll wins: %lf, First roll loses: %lf, Second roll wins: %lf, Second roll loses: %lf. ", winf, lostf, winp, lostp);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.