Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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. image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions