Question: MATLAB using while loops (no for loops) Game of Pig For this activity, you will re-create the Game of Pig. It is a simple game
MATLAB using while loops (no for loops)



Game of Pig For this activity, you will re-create the Game of Pig. It is a simple game of chance with two players using a single die. Each player takes turns rolling the die and the first person to reach 100 points wins. Here are the rules: If you roll a 1 (called the pig), your turn is automatically over and you lose all points earned that round If you roll a 2-6, those points are added to your score You may choose to either roll again or end your turn (thus keeping points you have earned in this round) Your goal is to write a MATLAB script so one player can play Pig. You do not need to make the game for two players! Do the following steps: Display to the user their current turn and score Display a random number from 1-6 for the dice roll If the roll was a 1, the user loses all points for the round and starts the next turn Otherwise, ask the user if they would like to roll again or keep their current score The game should end when the user reaches 100 points Sample Output Example Output 1 (Your output will probably be different!): Turn 1 with 0 points: Roll: 5 Roll again? (y): y Roll: 2 Roll again? (y): y Roll: 2 Roll again? (y): y Roll: 6 Roll again? (y): y Roll: 6 Roll again? (y): y Roll: 4 Roll again? (y): n Turn 2 with 25 points: Roll: 4 Roll again? (y): y Roll: 2 Roll again? (y): y Roll: 4 Roll again? (y): y Roll: 3 Roll again? (y): y Roll: 5 Roll again? (y): y Roll: 4 Roll again? (y): y Roll: 3 Roll again? (y): n Turn 3 with 50 points: Roll: 6 Roll again? (y): y Roll: 5 Roll again? (y): y Roll: 4 Roll again? (y): y Roll: 6 Roll again? (y): y Roll: 5 Roll again? (y): y Roll: 6 Roll again? (y): y Roll: 4 Roll again? (y): y Roll: 5 Roll again? (y): y Roll: 6 Roll again? (y): y Roll: 3 It took you 3 turns to get to 100 points! Example Output 2 (Your output will probably be different!): Turn 1 with 0 points: Roll: 4 Roll again? (y): y Roll: 2 Roll again? (y): y Roll: 1 Pig! You lose all points for this round... Turn 2 with 0 points: Roll: 5 Roll again? (y): y Roll: 6 Roll again? (y): y Roll: 3 Roll again? (y): y Roll: 4 Roll again? (y): n Turn 3 with 18 points: Roll: 5 Roll again? (y): y Roll: 5 Roll again? (y): y Roll: 3 Roll again? (y): y Roll: 5 Roll again? (y): y Roll: 3 Roll again? (y): n Turn 4 with 39 points: Roll: 2 Roll again? (y): y Roll: 3 Roll again? (y): y Roll: 3 Roll again? (y): y Roll: 3 Roll again? (y): y Roll: 2 Roll again? (y): y Roll: 3 Roll again? (y): n Turn 5 with 55 points: Roll: 5 Roll again? (y): y Roll: 5 Roll again? (y): y Roll: 2 Roll again? (y): y Roll: 1 Pig! You lose all points for this round... Turn 6 with 55 points: Roll: 5 Roll again? (y): y Roll: 4 Roll again? (y): y Roll: 6 Roll again? (y): y Roll: 6 Roll again? (y): y Roll: 2 Roll again? (y): n Turn 7 with 78 points: Roll: 5 Roll again? (y): y Roll: 4 Roll again? (y): y Roll: 2 Roll again? (y): y Roll: 4 Roll again? (y): y Roll: 3 Roll again? (y): y Roll: 5 It took you 7 turns to get to 100 points
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
