Make a program that will simulate the game of craps. Roll a pair of dice first r
ID: 3863100 • Letter: M
Question
Make a program that will simulate the game of craps. Roll a pair of dice first roll If first roll is 7 or 11, Win If first roll is 2, 3, or 12, "lose" If first rol is something else, keep rolling until you get 7 or the same total as first roll: 7 lose Same as first roll win Examples: First roll 11 win First roll 3 lose First roll 6 First roll 8 10 11 12 6 win 7 loses Requirements Use a do-while loop Make a function called rollDice that simulates rolling a pair of dice. This function simulates rolling a pair of dice. It returns a random number between 2 and 12. rollDice To simulate a roll of dice, think of 2 separate dice. Die 1 Die 2 roll (rando Grand0 6+ 1); use this one 0%6+1) generates a random number between 1 and 6 The following simulates 1 big die that has ll sides from 2 to 12 roll (rand0 11 2); Don't use this generates a random number between 2 and 12Explanation / Answer
#include #include #include #include #define WON 0 #define LOSE 1 int rollDice(void); int playGame(void); int rollDice(void) { return ((rand() % 6) + 1); } int playGame(void){ int dice_1 = 0; int dice_2 = 0; int sum = 0; time_t t; srand(time(&t)); printf("ROLL THE DICE WITH [ENTER] "); dice_1 = rollDice(); dice_2 = rollDice(); sum = dice_1 + dice_2; if (sum == 7 || sum == 11){ printf("Congratulations you roll %d and WON at your first try!", sum); } else { printf("Your roll was %d ,you lose try agian. ", sum); } return 0; } int main (void){ playGame(); }Related 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.