Im doing an exercise and almost have it down bur I can't figure out how to get the total of the die rolls to add up. I am new to coding so I don't know anything too complex yet so the most basic way to do it is what I need help with. Thank you for helping!
This it the goal:
You are coding a simple game called Pig. Players take turns rolling
a die. The die determines how many points they get. You may get
points each turn your roll (turn points), you also have points for the
entire game (grand points). The first player with 100 grand points is
the winner. The rules are as follows:
Each turn, the active player faces a decision (roll or hold):
Roll the die. If it’s is a:
1: You lose your turn, no turn total points are added to your
grand total.
2-6: The number you rolled is added to your turn total.
Hold: Your turn total is added to your grand total. It’s now the
next player’s turn.
This is what I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;
int PlayerOneTurn(int playerOneTotal);
int PlayerTwoTurn(int playerTwoTotal);
int main()
{
int playerOneScore;
int playerTwoScore;
int playerOneTotal;
int playerTwoTotal;
int turnScore;
srand(time(NULL));
do
{
playerOneTotal=PlayerOneTurn(playerOneScore)+playerOneTotal;
if(playerOneTotal >=100)
{
cout<<"Player 1 wins."<<endl;
}
playerTwoTotal=PlayerTwoTurn(playerTwoScore)+playerTwoTotal;
if(playerTwoTotal>=100)
{
cout<<"Player 2 wins."<<endl;
}
}
while (playerOneTotal<100 && playerTwoTotal<100);
return 0;
}
int PlayerOneTurn(int playerOneTotal)
{
int playerOneScore=0;
int turnScore=0;
int stayOrRoll;
cout<<"Player 1 turn."<<endl;
cout<<"Press 1 to roll or 2 to stay"<<endl;
cin>>stayOrRoll;
if (stayOrRoll==1)
{
turnScore=rand()%6+1;
if(turnScore==1)
{
cout<<"End of turn, next players turn."<<endl;
playerOneScore=playerOneScore;
}
else
{
playerOneScore=playerOneScore + turnScore;
cout<<"Player 1 score = "<<playerOneScore<<endl;
}
}
return playerOneScore;
}
int PlayerTwoTurn(int playerTwoTotal)
{
int playerTwoScore=0;
int turnScore=0;
int stayOrRoll;
cout<<"Player 2 turn."<<endl;
cout<<"Press 1 to roll or 2 to stay"<<endl;
cin>>stayOrRoll;
if (stayOrRoll==1)
{
turnScore=rand()%6+1;
if(turnScore==1)
{
cout<<"End of turn, next players turn."<<endl;
playerTwoScore=playerTwoScore;
}
else
{
playerTwoScore=playerTwoScore + turnScore;
cout<<"Player 2 score = "<<playerTwoScore<<endl;
}
}
return playerTwoScore;
}
|
I don't understand how to get the totals of the players to add up