Functions & Selections

I am trying to create a game where:

1.The first player’s turn starts by rolling five six-sided dice.

2.If the average of the dice is less than or equal to 3, the player gets 0 points for this turn and play passes to the next player.

3.If the average of the dice is greater than 3 (there’s approximately a 70% chance of this with five dice), the player is safe, adds the total of the dice to their turn score, and chooses one of the following options:

a.They can roll again, but this time with one fewer die. For example, if the player gets a total of 22 with five dice, they can keep 22 for their turn score and roll again with four dice. However, they run the risk of fracking out again and ending their turn with 0 points. If they do not frack out, however, their turn score increases with the total of that roll. They can continue to do this all the way to rolling just one die. After that die has
been rolled, play will automatically pass to the next player.

b.They can declare their turn over, add their turn score to their total game score, and pass the dice to the next player. Note that the total game score is not affected by fracking out. Only the turn score can be reset to zero.

4.The next player can start their turn either with 0 points and five dice, or the current number of points from the other player and however many dice are left at that point.

I am allowed to use functions, loops and selection.

Following is a sample run that I am trying to achieve:

Let's Play Frack!

Enter player 1’s name: Elon
Enter player 2’s name: Jeff

How many points are we playing to? 50

Elon’s turn 1

Enter R to roll 5 dice: R // Elon starts with 5 dice

Your dice are: 6 2 4 1 4
The total is 17, and the average is 3.4 // Elon is safe, and gets to choose whether to roll again or to pass 4 dice to the next player.

Elon is safe! Your turn score is now 17.
Enter R to roll again, or P to pass: R // He chooses to roll again.

Your dice are 3 4 5 2
The total is 14, and the average is 3.5 // Safe again!

Elon is safe! Your turn score is now 31. // This time Elon chooses to bank his points, end his turn and pass his remaining 3 dice to Jeff.
Enter R to roll again, or P to pass: P

Jeff’s turn 1

Do you want to start from zero (Z), or with Elon’s points (P) and 3 dice? P

Your dice are 3 2 1 // Jeff chooses to continue where Elon left off,but is unlucky and ends with 0 points this turn.

The total is 6, and the average is 2.0

Frack! You get 0 points.

At the end of round 1, the score is Elon: 28 and Jeff: 0

Elon’s turn 2

Enter R to roll 5 dice: R

Your dice are: 6 3 3 1 1
The total is 14, and the average is 2.8

…play should continue until one of the players reaches 50 points.

I am stuck and I really need some help.


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
  #include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std; 

string getPlayerOneName();
string getPlayerTwoName();
int getUserInputForPoints();

int main()
{
	cout << "Let's Play Frack! " << endl << endl;
	string nameOne = getPlayerOneName();
	string nameTwo = getPlayerTwoName();
	int points = getUserInputForPoints();
	
	int compChoice;
	srand(unsigned(time(NULL)));
	compChoice = rand() % 5 + 1;

	system("pause");
	return 0;
}

string getPlayerOneName() // -----------------------------------------------------

{
	string playerOne;
	cout << "Enter player 1's name: ";
	cin >> playerOne;
	return playerOne;
}

string getPlayerTwoName() // -----------------------------------------------------

{
	string playerTwo;
	cout << "Enter player 2's name: ";
	cin >> playerTwo;
	return playerTwo;
}

int getUserInputForPoints() // ---------------------------------------------------

{
	int totalPoints;
	cout << "How many points are we playing to? ";
	cin >> totalPoints;

	while (totalPoints < 0)
	{
		cout << "Please re - enter the points again: ";
		cin >> totalPoints;
	}
	return totalPoints;
}
Use a " do{....} while(score<50); " loop.
Last edited on
Topic archived. No new replies allowed.