92%(12)11 out of 12 people found this document helpful
This preview shows page 35 - 40 out of 40 pages.
string HIGH = “You guessed too high!”string LOW = “You guessed too low!”housekeeping()while guess not equal to myRandomNumberdetailLoop()endwhilefinishUp()stophousekeeping()myRandomNumber = random(LIMIT)output PROMPT, LIMIT input guess
2.Create the logic for a game that simulates rolling two dice by generating two numbersbetween 1 and 6 inclusive. The player chooses a number between 2 and 12 (the
Programming Logic and Design, 9eSolutions 5-37Pseudocode:startDeclarationsnum dice1num dice2
3.Create the logic for the dice game Pig, in which a player can compete with the computer. The object of the game is to be the first to score 100 points. The user and
Programming Logic and Design, 9eSolutions 5-39When the computer does not roll a 1 and can choose whether to roll again, generate a random value of 1 or 2. The computer will then decide to continue when the value is 1 and decide to quit and pass the turn to the player when the value is not 1.Answer: A sample solution is as follows:Pseudocode:startDeclarationsnum dice1num dice2num userCountnum computerCountnum userTurnnum LIMIT = 2num WIN_NUM =100housekeeping()while computerCount < WIN_NUM AND userCount < WIN_NUMdetailLoop()endwhilestophousekeeping()output ”The first to 100 wins the game of Pig”userCount = 0computerCount = 0userTurn = 1returndetailLoop()if userTurn = 1 thenoutput “User’s turn to roll the dice”