Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program. You are only allowed to use the following functions : #include<

ID: 3810206 • Letter: W

Question


Write a program. You are only allowed to use the following functions :
#include<iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>

Writing a program to simulate a Dice Game For al programs for the rest of the semester you must provide good intema documentation, The Mat of your source code should be comments that include your nos program solves name and date as the first wne, followed by a description of the problem the Throughout your program. use meaning variable names. Aa function definitions must stat a code that needs describes the task the nditions with of explanation needs to be preceded by a comment and Postconditons for the function. Any area block. A popular game of chance is a dice game known as "craps. You are to winte a program to simulate a craps game, The A player rows two dice. Ir the sum is 7 ar 11 on the first throw, the player wins. Af the sum is 2, 3, or 12 on the list throw (called "craps", the player Moses, the sum is 4. on the Mrsr that surm becomes the players point" Myou don' win or Mose on the Msf row you must Dornbnue roi the dice until you win or lose. If you make your poinr you win, you roo a 7 you lose. You will use C. library functions to generate random numbers to simulate rolling dice. You will need to use two lorary in the "cstdiib header fle and one library function contained in the

Explanation / Answer

#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;
int flag=0;
void printDice(int dice)
{
   if(dice==1)
   {
       cout<<" ******* * * * * * * * * * * * *******";
   }
   else if(dice==2)
   {
       cout<<" ******* * * * * * ** * * * * * *******";
   }
   else if(dice==3)
   {
       cout<<" ******* * * * * * *** * * * * * *******";
   }
   else if(dice==4)
   {
       cout<<" ******* * * * ** * * ** * * * * * *******";
   }
   else if(dice==5)
   {
       cout<<" ******* * * * ** * * * * * ** * * * *******";
   }
   else if(dice==6)
   {
       cout<<" ******* * * * ** * * ** * * ** * * * *******";
   }
}
int Dieroll()
{
   int die;
   die=rand() % 6 + 1;
   return die;
}
int SumDiece(int die1,int die2)
{
   int sum=0;
   sum=die1+die2;
   return sum;
}
int main()
{
int dice1, dice2 = 0;
int rollDice;
char repeat = 'y';


while (repeat == 'y' || repeat == 'Y')
{   
srand(time(0));
   dice1 =Dieroll();
   printDice(dice1);
dice2 = Dieroll();
   printDice(dice2);
rollDice = SumDiece(dice1,dice2);

cout << " The sum of Your rolls is: " << rollDice;
if (rollDice == 7 || rollDice == 11)
{
cout << ". Winner !" << endl ;
}

else if (rollDice == 2 || rollDice == 3 || rollDice == 12)
{
cout << ". You lose!" << endl;
}

else if (rollDice == 4 || rollDice == 5 ||rollDice == 6 ||rollDice == 8 || rollDice == 9 || rollDice == 10)
{   
do
{
  
      
       //srand(time(0));
       dice1 =Dieroll();
       printDice(dice1);
   dice2 = Dieroll();
       printDice(dice2);
   int sum2 = SumDiece(dice1,dice2);
   cout << " The sum of Your rolls is: " << sum2;

if( sum2 == rollDice )
{
cout << ". Winner !" << endl;
flag=1;
break;
}
else if( sum2 == 7 )
{
cout << ". You Lose!" << endl;
flag=1;
break;
}
}while(flag!=1);
}
cout <<"Another game? Y(es) or N(o)" << endl;
cin >> repeat;

if(repeat == 'n' || repeat == 'N')
{
cout << "Thank you for playing!"<< endl;
}

}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote