Question
Hello, I have an assignment where I need to add these certain specifications to the code and I need some help with. These are the
Hello, I have an assignment where I need to add these certain specifications to the code and I need some help with. These are the specifications:
"C" Specification Bundle. // Specification C1 - Fixed Seed Set the random number seed to a specific integer. That way, it will always generate the same random number sequence - easier to fix bugs that way. // Specification C2 - Student Name Allow name to accept first plus last name (ie 2 words). Display it somewhere in the output. // Specification C3 - Numeric Menu Use a numeric menu to collect the human players actions. See figure 1 for an example menu. // Specification C4 - Bulletproof Menu
Detect and re-prompt if incorrect data (i.e. not 1, 2, or 3) is en- tered.
"C" Bundle Menu Options. 1. 1. Roll 2. 2. Hold 3. 3. Quit Figure 1: Allowable menu options for this bundle.
"B" Specification Bundle. // Specification B1 - Display Turn Stats Keep track of the points each player scores each turn as well as the overall points both sides have each turn in the game. //Specification B2 - Display Due Date Display the date this assignment is due in your program greeting section. // Specification B3 - Hi Score on Heap Store the games high score in a variable in the heap. Dont forget to clean up after yourself before the program quits. // Specification B4 Display High Score Display the value you stored in B3 on the console at the end of the game. "A" Specification Bundle. // Specification A1 - D6() function This method returns a randomly generated int between 1 and 6 every time its called. Replace the code which does that in your assignment with this. // Specification A2 - RandomNumber() function Create a function which generates a random number between arguments lo and hi.
pig (pig) 3
// Specification A3 - Protect RandomNumber() input Using an if statement, protect your RandomNumber() function from bad data. Return a -1 error code if RandomNumber() receives bad input. Argument rules are: 1. Hi must be greater than lo. 2. Lo cannot be less than 1. 3. Hi cannot be greater than 100. // Specification A4 - Protect RandomNumber() output Make sure your RandomNumer() function doesnt send bad output. Use an if statement before your return to make sure the random
number isnt greater than 100. Return a -2 error code if you gener- ate bad output.
This is my code:
#include
#include
#include
#include
using namespace std;
// Function to roll a dice and returns its value
int rollDie()
{
// Generates random number between 1 and 6
int diceValue = 1 + (rand() % 6);
return diceValue;
}
// Function to roll dice for user
int userTurn(int &userTotalScore)
{
int userScore = 0;
bool runningStatus = true;
// To store user choice
string userChoice;
int diceValue = 0;
do
{
diceValue = rollDie();
if (diceValue == 1)
{
cout
runningStatus = false;
}
else
{
// Adds the dice value to score
userScore += diceValue;
cout
// Specification C3 - Numeric Menu (Lines 39-49)
cin >> userChoice;
if (userChoice == "2")
{
// Calculates total score
userTotalScore += userScore;
runningStatus = false;
}
}
if (userChoice == "3")
exit(0);
} while (runningStatus);
return 0;
}
int computerTurn(int &compTotalScore)
{
bool runningStatus = true;
int computerScore = 0;
int diceValue = 0;
do
{
// Calls the function to roll dice and stores the return value
diceValue = rollDie();
if (diceValue == 1)
{
cout
computerScore = 0;
runningStatus = false;
}
else
// Adds the dice value
computerScore += diceValue;
} while (computerScore
// Calculates the total score
compTotalScore += computerScore;
return 0;
}
//Specification C2 - Student Name
void playerName()
{
string fName, lName;
string fullName;
cout
cin >> fName;
cout
cin >> lName;
fullName = fName + " " + lName;
cout
}
// Main Function
int main()
{
// Specification C1 - Fixed Seed
unsigned seed = 123;
srand(seed);
playerName();
srand((int)time(0));
int userTotalScore = 0;
int compuerTotalScore = 0;
while (userTotalScore
{
userTurn(userTotalScore);
computerTurn(compuerTotalScore);
cout
}
// Checks if user total score is greater than or equals to 100
// then user win
if (userTotalScore >= 100)
cout
else
cout
return 0;
}
The output should look something like this:
make -s ./main Enter user name: User Player score : Computer score : 0 Its User's turn : 1: Roll 2: Hold 3: Quit 1 Rolled : 5 Turn Score : 5 1: Roll 2: Hold 3: Quit 2 Total Turn Score : 5 Player score : 5 Computer score : 0 . Its computer's turn : Rolled : 6 Turn Score : 6 Rolled : 3 Turn Score : 9 Rolled : 1 Turn Score : 0 Total Turn Score : 0 Player score : 5 Computer score : 0 : Its User's turn : 1: Roll 2: Hold 3: Quit A]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