Oct-10-2018, 01:17 PM
You really need two while loops. The first/outer while loop is for the game, and continues until one player gets over 100. Note that your current while loop doesn't do that. Your loop will keep playing until both players get over 100.
The second/inner loop is for the player's turn. That keeps going until they say "stop" or roll a 1. You want to roll the dice at the top of that loop, then check for the 1 and either break or add it to a variable keeping track of the turn score, then ask if they want to keep going. At the end of the loop update that player's total turn score.
How you handle the two players is up to you. You could have a copy of the second loop that handles the second player, or a for loop between the two while loops that loops through the two players. Although based on the instructions your teacher is expecting a for loop. Of course, you could eliminate the for loop and just change the turn variable each time through the outer while loop. You would then need a conditional to see whether to ask (for the human player) or just keep going (for the computer player).
Personally, I don't like this version of two-die pig. You have a 10 in 36 chance of losing the turn score, compared to a 6 in 36 chance in standard one-die pig. Plus the 1 in 36 chance of losing your whole score. But it's what your teacher chose.
The second/inner loop is for the player's turn. That keeps going until they say "stop" or roll a 1. You want to roll the dice at the top of that loop, then check for the 1 and either break or add it to a variable keeping track of the turn score, then ask if they want to keep going. At the end of the loop update that player's total turn score.
How you handle the two players is up to you. You could have a copy of the second loop that handles the second player, or a for loop between the two while loops that loops through the two players. Although based on the instructions your teacher is expecting a for loop. Of course, you could eliminate the for loop and just change the turn variable each time through the outer while loop. You would then need a conditional to see whether to ask (for the human player) or just keep going (for the computer player).
Personally, I don't like this version of two-die pig. You have a 10 in 36 chance of losing the turn score, compared to a 6 in 36 chance in standard one-die pig. Plus the 1 in 36 chance of losing your whole score. But it's what your teacher chose.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures