Question: I need it in C++ Write a function named rollDice that simulates the tossing of a multi-sided dice. It should take in parameters that depict
I need it in C++
Write a function named rollDice that simulates the tossing of a multi-sided dice. It should take in parameters that depict how many sides (faces) are on the dice (numbered 1 to the number of sides). When you call the function, it should generate a random number in the range of 1 through the number of dice sides. It should return the number rolled. Then you should have another function called playGame. This function take in a parameter that lists the goal of the game. You will alternate roles for each of two players, by calling rollDice (from playGame). The first player to get a score that is equal to that number without going over wins. The function should show that status of each players roles. Then it should return 1 or 2 (representing whether player 1 or player 2 won the game. Your main function should call playGame. Then it should print out which player won the game (from main).
Clarification:
You should place the function prototypes in a file called Functions.h The function prototype has a semi-colon at the end. e.g
int rollDice (int sides);
Implementation detail 2: Your functions.h file should have a guard against duplication, e.g.
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
(function prototypes)
#endif
The user enters only faces of dice and the goal of the game and the program should automatically play and alternate between Player1 and Player2. Whoever gets to the goal first without going over it wins. For example, if faces are 6 and goal is 20.
Player1 gets 3, 4, 6, 6 respectively for first 4 turns. Untill this point the Player1 has 19 points and will win only if gets exactly 1. If he/she gets 2, 3 or any other numbers, its not a win. For Player2, it's the same. The game continues till one gets to exactly 20 first. Print out the output and score for each turn.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
