Question: A simple Game Program of PIG. Write a Swift code for it. Game of Pig .Create variables to store the human and the computer's scores,

A simple Game Program of PIG. A simple Game Program of PIG. Write a Swift code for it.

Write a Swift code for it.

Game of Pig .Create variables to store the human and the computer's scores, the current turn's Encapsulate game in a while loop to allow more than one round of turns to occur, Program Plan: total, the roll of one die, and the user's choice to roll or hold until either score is 100 or greater. Inside the while loop: Create a while loop for the human, and another for the computer that will be reached after it Inside the human's while loop, ask the human if they want to roll or hold, and store the input in the choice variable .Use an if-else statement: if they want to roll, use the given line of code to simulate .If the roll is a 1, end the turn; otherwise, add the roll to the current turn total as Create the same structure in the computer's while loop, except instead of asking it a dice roll; if they hold, add the current turn total to the score, then end the turn. well as the human s score. whether it wants to roll or hold, check if the current turn's score is greater than on equal to 20; if so, then tell it to hold, otherwise, tell it to roll. Game of Pig .Create variables to store the human and the computer's scores, the current turn's Encapsulate game in a while loop to allow more than one round of turns to occur, Program Plan: total, the roll of one die, and the user's choice to roll or hold until either score is 100 or greater. Inside the while loop: Create a while loop for the human, and another for the computer that will be reached after it Inside the human's while loop, ask the human if they want to roll or hold, and store the input in the choice variable .Use an if-else statement: if they want to roll, use the given line of code to simulate .If the roll is a 1, end the turn; otherwise, add the roll to the current turn total as Create the same structure in the computer's while loop, except instead of asking it a dice roll; if they hold, add the current turn total to the score, then end the turn. well as the human s score. whether it wants to roll or hold, check if the current turn's score is greater than on equal to 20; if so, then tell it to hold, otherwise, tell it to roll

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!