Question
in C++ Dice Game John and Pete are playing a game, John has nine 4-sideddice and Pete has six 6-sided dice. They both roll their
in C++ Dice Game
John and Pete are playing a game, John has nine 4-sideddice and Pete has six 6-sided dice. They both roll their dice and the winner is the one with the highest number, in case they roll the same number it is a draw. Write a function that simulates 10 games, keep track and print each of the ir scores. After the 10th game print the overall score, declare a winner and print the best roll of each player.
can you explain it so I can get a better understanding
Here is MY CODE
#include
#include
using namespace std;
int main()
{
int numThrows = 10;
int diceSizeP = 6, diceSizeJ = 4;
int resultsP, resultsJ;
int totalP;
int totalJ;
srand(time(NULL));
for (int i = 0; i < numThrows; i++)
{
resultsP = rand() % 36 + 6;
totalP += resultsP;
cout << "Pete rolled a " << resultsP << endl;
resultsJ = rand() % 36 + 4;
totalJ += resultsJ;
cout << "John rolled a " << resultsJ << endl;
if (resultsP != resultsJ){
if (resultsP > resultsJ)
cout << "Pete answer is higher than John, Pete wins. ";
else if (resultsP < resultsJ)
cout << "John answer is higher than Pete, John wins. ";
else
cout << "Draw both numbers are equal";
return 0;
}
}
cout << "The total is Pete " << totalP << " and Pete's best roll was " << endl;
cout << "The total is John " << totalJ << " and John's best roll was " << endl;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started