Answer to Question #278739 in Algorithms for Moon

Question #278739

Tony is writing a program to calculate a player's score in a dice game. A player starts with a score of 0 and rolls a dice, numbered 1 to 6, as many times as they want. After each roll they add the number the dice lands on to their score. The aim is to get as close to 21 as possible. If you go over 21 you get a score of 0. Write Tony's program as an algorithm. 



1
Expert's answer
2021-12-12T01:17:44-0500
Start
   Declare variable score
   Declare variable rollDice
   Declare variable answer
   Set answer="y"
   While answer="y" do
       Set rollDice = generate random value 1-6
       if  rollDice >=18 and rollDice <=21 then
          score+=rollDice
       else 
         score=0
       end if
       Display message "Do you want to play again? (y/n): "
       Read answer
   End while
   Display score
Stop

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS