Question: Write a complete C + + program. In this program you have to write 2 functions in addition to the main function. 1 . Function
Write a complete C program. In this program you have to write functions in addition to the main function.
Function #:
Write function throwDice that generates a random number between and The function should return the generated number.
int throwDice;
Function #:
Write function play to perform the following:
Declare the required local variables: score, dice dice
Initialize variable score to
Loop times to do the following:
o Call the function throwDice and store the returned value in variable dice
o Call the function throwDice again and store the returned value in vriable dice
o Update score by adding to its current value the value of dice and the value of dice
After the loop, check the value of score, if it is above then return true; otherwise retun false.
bool play;
Write a complete program to do the following in the main:
Call the function play
Display Win if the returned value of calling the function play is true, otherwise, display lose
Repeat the above two steps until the user decides to stop playing and exit the program. why is this program not working properly: #include
#include For random number generation
using namespace std;
Function to throw a dice and return the result
int throwDice
static randomdevice rd;
static mt genrd;
static uniformintdistribution distribution;
return distributiongen;
Function to play the game
bool play
int score ;
int dice dice;
Loop times to throw the dice and update score
for int i ; i ; i
dice throwDice;
dice throwDice;
score dice dice;
Check if score is above
if score
return true;
else
return false;
int main
char choice;
do
cout "Playing the game..." endl;
if play
cout "Congratulations! You won." endl;
else
cout "Sorry, you lost." endl;
cout Do you want to play again? YN: ;
cin choice;
while choice Y choice y;
cout "Thanks for playing. Goodbye!" endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
