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

The project\'s objective is to create a very simple Jeopardy Dice game in which

ID: 3814112 • Letter: T

Question

The project's objective is to create a very simple Jeopardy Dice game in which one player the user) competes against the computer to reach 100 points. Each turn, the player or the computer repeatedly rolls a die until either a 1 is rolled or the player holds and scores the sum of the rolls (i.e. the turn totaD. At any time during a player's turn, the player is faced with two decisions: roll If the player rolls a o 1: the player scores 1 point and it becomes the opponent's turn o 2- 6: the number is added to the player's turn total and the player's turn continues. hold The turn total is added to the player's score and it becomes the opponent's turn Implement a game of Jeopardy Dice where the user plays against a computer player that rolls until a 1 is rolled, or the turn total is greater than or equal to 25, or the score plus the turn total is greater than or equal to 100. The player who takes the first turn in the game is chosen randomly Requirements: 1) Your program should contain at least three functions. 2) Your program should interactively display the player and the computer s choices, the dice rolls, the running turn total and the running score after each turn

Explanation / Answer

#include <iostream>
#include<stdlib.h>
#include <cstdlib>

#include <ctime>
#include<time.h>

using namespace std;
void plr_turn();
void comp_turn();
void winner(int);

int pdice,cdice,p_turn_tot,c_turn_tot, plr_score,comp_score;
int main() {
   int turn;
  


  
   cout<<"---Jeopardy Dice--- ";
   cout<<"Press any key to know who rolls first ";
   getchar();
       turn=1+rand()%2;
   if(turn==1)
   {
       cout<<"It's your turn"<<endl;
       plr_turn();

   }

   else
   {
      
       cout<<"It's computer's turn ";
           comp_turn();
   }
   return 0;
}

void plr_turn()
{ int ch;

srand(time(NULL));
   cout<<"Press enter to roll the dice: ";
   getchar();
plrroll:       pdice=1+rand()%6;
       cout<<" dice rolled: "<<pdice;
       if(pdice==1)
       {   plr_score+=1;
       cout<<" It's computer's turn now: ";
           comp_turn();
       }
       else
       {
           p_turn_tot+=pdice;
           cout<<" Enter 1 to roll or 2 to hold: ";
label:   cin>>ch;
           switch(ch)
           {
           case 1:
               goto plrroll;
               break;
           case 2:
               plr_score+=p_turn_tot;
               if(plr_score>=100)
                   winner(1);
               else{
                   cout<<" It's computer's turn now: ";
                   comp_turn();
               }
               break;
           default: cout<<"Invalid choice! enter again: ";
                       goto label;

                       break;
           }

       }
}

void comp_turn()
{
srand(time(NULL));

comproll:   cdice=1+rand()%6;
   cout<<" computer rolled: "<<cdice;
   if(cdice==1)
   {   comp_score+=1;
       cout<<" It's your turn now"<<endl;
       plr_turn();
   }
   else
   {
       c_turn_tot+=cdice;
       if(c_turn_tot>=25)
       {   comp_score+=c_turn_tot;
           cout<<" It's your turn now"<<endl;
       plr_turn();
       }

       else if(comp_score>=100)
       {
      
           winner(2);
       }
       else
           goto comproll;
   }
  
}

void winner(int flag)
{
   switch(flag)
   {
   case 1:   cout<<" Congrats! You are the winner";
           exit(0);
           break;
   case 2: cout<<" Sorry! The winner is the computer";
           exit(0);
           break;
   }
}