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.
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
Comments
Leave a comment