The purpose of this program is to have a dice game where a dice isrolled and tha
ID: 3617581 • Letter: T
Question
The purpose of this program is to have a dice game where a dice isrolled and that is the forbidden number that a player cannot beton. Next each player picks a number and an amount to bet on it ifno one wins the money goes into a house account. The part I amhaving trouble with is checking to make sure no one entered theforbidden number. I am also having trouble printing the playersnames who won and updating the balances. Here is what I have sofar. Thanks# include <stdio.h>
# include <time.h>
# include <stdlib.h>
int rollDice(void);
struct playerRec {
char lastName[100];
char firstName[100];
int bidAmount; // bid amount for every round
int bidNumber; // number bet on
double balance; // amount of money inplayers account
};
int main(void){
int forbiden, roll, n, houseAccount, endGame,tableAccount,i;
printf("Welcome! ");
printf("to a game with dice, here is how to play thecomputer will pick a forbidden number and each player will pick anumber other than that number a dice is rolled if you picked theright number YOU WIN!!! ");
forbiden = rollDice();
printf("the forbiden number is %d ",forbiden);
printf("How many players will be playing today? ");
scanf("%d",&n);
struct playerRec player[n];
for(i=0;i<n;i++){
printf("For player %d ",i+1);
printf("Enter last name: ");
scanf("%s",&player[i].lastName);
printf("Enter first name: ");
scanf("%s",&player[i].firstName);
printf("Enter bid Amount: ");
scanf("%s",&player[i].bidAmount);
printf("Enter int bid Number: ");
scanf("%s",&player[i].bidNumber);
printf("Enter balance: ");
scanf("%s",&player[i].balance);
}
/*make sure no one entered the forbiden number*/
houseAccount = 0;
endGame = 1;
while (endGame == 0){
tableAccount = //add all players bids
printf ("the table account is %d ", tableAccount);
roll = rollDice();
/*print players who won and lost and update theirbalences*/
/*print the house account total*/
printf("would you like to play again? enter 1 if you wouldlike to end the game 0 to continue ");
scanf( "%d ", &endGame);
}
}
int rollDice(void){
int die;
die = 1 + ( rand() % 6);
return die;
}
Explanation / Answer
# include # include # include int rollDice(void);struct playerRec {char lastName[100];char firstName[100];int bidAmount; // bid amount for every round int bidNumber; // number bet ondouble balance; // amount of money in players account};int main(void){int forbiden, roll, n, houseAccount, endGame=1, tableAccount,i;while(endGame){printf("Welcome! ");printf("to a game with dice, here is how to play the computer will pick a forbidden number and each player will pick a number other than that number a dice is rolled if you picked the right number YOU WIN!!! ");forbiden = rollDice();printf("the forbiden number is %d ",forbiden);printf("How many players will be playing today? ");scanf("%d",&n);int won=0;struct playerRec player[n];roll = rollDice();for(i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.