Question: Write a program that simulates the game of craps, which is played with two dice. On the first roll, the player wins if the sum
Write a program that simulates the game of craps, which is played with two dice. On the first roll, the player wins if the sum of the dice is 7 or 11. The player loses if the sum is 2, 3, or 12. Any other roll is called the point, and the game continues. On each subsequent roll, the player wins if he or she rolls the point again. The player loses by rolling a 7. Any other roll is ignored and the game continues. At the end of the each game, the program will ask the user whether or not to play again. When the user enters a response other than y or Y, the program will display the total number of wins and losses and then terminate. Specifications: Write the program using three functions: main, rollDice, and playGame. Use the following function prototypes: int rollDice(void); bool playGame(void); rollDice() should generate two random numbers, each between 1 and 6, and return their sum. Use the rand() function to generate random numbers. playGame() should play one craps game (calling rollDice() as many times as necessary to determine the outcome of each dice roll); it will return true if the player wins and false if the player loses (t. play_game is also responsible for displaying messages showing the results of the players dice rolls. main will call play_game repeatedly, keeping track of the number of wins and losses, and displaying the You WIN! and You lose! messages. At the beginning main, after displaying a Welcome to Craps message, you should prompt the user to enter a random seed (to satisfy the grader program). Finally, use the exit() function and the EXIT_SUCCESS constant to exit your program (which are both defined in ). From this point forward, each of your programs should use the exit() function to terminate. In other words, to exit the program: return(EXIT_SUCCESS); As an example, if you execute the program with the following underlined inputs, the output will be: ~> main.o Welcome to Craps Please enter a random seed: 23 You rolled: 4 Your point: 4 You rolled: 8 You rolled: 8 You rolled: 5 You rolled: 6 You rolled: 11 You rolled: 7 You lose! Play again? (Y/N): n Wins: 0 Losses: 1
this is what i have so far
#include
using namespace std;
int rollDice(void); bool playGame(void);
int main(int argc, char** argv) { unsigned int seed; int iter = 1, totalWins = 0,point; cout << "Welcome to Craps" << endl; cout << "Please enter a random seed: "; cin >> seed; int score = rollDice(void); if (score == 7||score == 1) { cout << "You win"; totalWins++; } else if (score == 2||score == 3|| score == 11) { cout << "you lose"; } point = score; cout << "point" << point; bool playGame(void); int score = rollDice(void); cout << "point" << score; if(score == point) { cout << "you win"; point = score; totalWins++; } else if(score == 7) { cout << "you lose"; }
exit(EXIT_SUCCESS); }
int rollDice(void) { int die1, die2; die1 = rand()%6 +1; die2 = rand()%6+1; return(die1 + die2); } bool playGame(void) { char choice; cout << "Play again?(Y/N): "; cin >> choice; if (choice == 'Y') { return true; } return false; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
