Question

can someone help me fix my jeopardy dice game I am having a hard time figuring...

can someone help me fix my jeopardy dice game I am having a hard time figuring out what i am doing wrong

#include
#include
using namespace std;

//this function makes a number between 1 and 6 come out just like a dice
int rollDie()
{
return (rand() % 6+1);
}
//this function asks the user with a printed statement if they want to roll the dice and gives instructions for yes and no (y/n)
void askYoNs(){
cout<<"Do you want to roll a dice (Y/N)?:"< }

void printScores(int turnTotal,int humanTotal,int compTotal){

int player;
int human;
if(player==human){
cout<<"Your turn total is "< }
else{
cout<<"computer turn total is "< }
cout<<"computer: "< cout<<"human: "< cout< }
int human;
int changePlayer(int player){
if(player==human)
return 1;
return human;
}
int process(int& turnTotal,int roll,int curr_player,int& humanTotal,int& computerTotal){
if(roll==2 || roll==5){
curr_player=changePlayer(curr_player);
turnTotal=0;
printScores(turnTotal,humanTotal,computerTotal);
}
else if(roll==4){
turnTotal=15;
///switch player
if(curr_player==human)
humanTotal+=turnTotal;
else
computerTotal+=turnTotal;
curr_player=changePlayer(curr_player);
turnTotal=0;
printScores(turnTotal,humanTotal,computerTotal);
}
else{ ///roll = 1 3 6
turnTotal+=roll;
cout<<"Your turn total is "< }
///if computer turnTotal becomes >=10
///then switch player
if(curr_player!=human && turnTotal >=10 ){
computerTotal+=turnTotal;
curr_player=changePlayer(curr_player);
turnTotal=0;
printScores(turnTotal,humanTotal,computerTotal);
}
return curr_player;
}
void game(){
int player=human;
int humanTotal=0;
int computerTotal=0;
int turnTotal=0;

if (turnTotal==0){
cout<<"Welcome to Jeopardy Dice!"< }
while(humanTotal<=80 && computerTotal<=80){
int roll=0;
if(player==human){
cout< cout<<"It is now human's turn "<   
cout< char YoN;
askYoNs();
cin>>YoN;
roll=rollDie();
cout<<"You rolled a "< player=process(turnTotal,roll,player,humanTotal,computerTotal);
if(YoN=='Y'){
humanTotal+=turnTotal;
player=1; ///switch player to Computer
printScores(turnTotal,humanTotal,computerTotal);
turnTotal=0;
continue;
}
}   
else
cout< cout<<"It is now computer's turn"< cout< roll=rollDie();
cout<<"Computer rolled a "< player=process(turnTotal,roll,player,humanTotal,computerTotal);
}///while ends here

///check who is winner
if(humanTotal>=80){
cout<<"Congratulations! human won this round of Jeopardy Dice!"< }
else{
cout<<"Congratulations! computer won this round of Jeopardy Dice!"< }
}
int main()
{
game();
return 0;
}

the basic rules for the game are

Game Mechanics

  • There are two players: the user and the computer, who alternate turns until one of them reaches 80 points or higher.

  • The user is always the first player and starts the game.

  • If any player reaches 80 points or more at the end of their turn, the game ends immediately and the other player does not get another turn.

  • During one turn the player(either the user or computer) accumulates turnTotal over a series of dice rolls.

    • If they roll a 2 or 5 , their turn ends and the turnTotal becomes 0.

    • If they roll a 4, their turn ends and turnTotal becomes 15 (irrespective what they collected up to that roll)

    • If they roll a 1, 3, or 6 , the value on the dice accumulates to turnTotal

    • The value on the dice is selected randomly during every roll.

  • At the end of the turn, turnTotal is accumulated to playerTotal(either user or computer based on the turn).

  • During a turn, before each roll, if the player is the user, they are given two options:

    • Continue rolling

    • Hold; if the user chooses to Hold the user’s turn ends and the turn is passed to the computer.

  • If the player is the computer, they will always continue rolling until their turn total reaches the value 10 or higher. If the turnTotal for the computer is 10 or higher, the computer’s turn ends and the turn is passed to the user.

Specifications:

  • Your solution must have an algorithm in pseudocode explaining how you are approaching the problem, step by step.

  • In the code runner we have main() function to test your game() function.

  • game() function is the driver function of your program and we will be testing your game() function on Moodle (CodeRunner).

    • The function does not take any input parameters.

    • The function does not return any value.

  • Your solution should have at least 3 functions apart from game()and rollDie() functions. Since the functions you will create will be called from inside the game() function, their definition should be above the definition of game().

  • You are given the freedom to design the functions of your choice. There are no restrictions on how many functions you create.

  • Creating functions that does nothing is not permitted. Each function should have a purpose and should be well documented.

  • Out of the three functions (or more) you will create,

    • One of the functions must have at least 1 input parameter

    • One of the functions must return a value

    • One of the functions should not return anything, but it should print/display something.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear student,

I tried to figure out the solution for the above problem hope you like it.

you can find the code below. if you have any doubt please comment below.

#include<iostream>
#include<stdlib.h>
using namespace std;
int player;
int human=0;
int rollDie()
{
   return (rand() % 6+1);
}

void askYoNs()
{
   cout<<"Do you want to roll a dice (Y/N)?:"<<endl;
}

void printScores(int turnTotal,int humanTotal,int compTotal)
{
   if(player==human)
   {
       cout<<"Your turn total is "<<turnTotal<<endl;
   }
   else
   {
       cout<<"computer turn total is "<<turnTotal<<endl;
   }
   cout<<"computer: "<<compTotal<<endl;
   cout<<"human: "<<humanTotal<<endl;
   cout<<endl;
}

int changePlayer(int player)
{
   if(player==human)
       return 1;
   return human;
}
int process(int& turnTotal,int roll,int curr_player,int& humanTotal,int& computerTotal)
{
   if(roll==2 || roll==5)
   {
       curr_player=changePlayer(curr_player);
       turnTotal=0;
       printScores(turnTotal,humanTotal,computerTotal);
   }
   else if(roll==4)
   {
       turnTotal=15;
       ///switch player
       if(curr_player==human)
       humanTotal+=turnTotal;
       else
       computerTotal+=turnTotal;
       curr_player=changePlayer(curr_player);
       turnTotal=0;
       printScores(turnTotal,humanTotal,computerTotal);
   }
   else
   { ///roll = 1 3 6
   turnTotal+=roll;
   cout<<"Your turn total is "<<turnTotal<<endl;
   }
   ///if computer turnTotal becomes >=10
   ///then switch player
   if(curr_player!=human && turnTotal >=10 )
   {
       computerTotal+=turnTotal;
       curr_player=changePlayer(curr_player);
       turnTotal=0;
       printScores(turnTotal,humanTotal,computerTotal);
   }
   return curr_player;
}
void game()
{
   player=human;
   int humanTotal=0;
   int computerTotal=0;
   int turnTotal=0;
  
   if (turnTotal==0){
   cout<<"Welcome to Jeopardy Dice!"<<endl;
   }
   while(humanTotal<=80 && computerTotal<=80)
   {
       int roll=0;
       if(player==human)
       {
           cout<<endl;
           cout<<"It is now human's turn "<<endl;
          
           cout<<endl;
           char YoN;
           askYoNs();
           cin>>YoN;
           if(YoN=='Y')
           {
               roll=rollDie();
               cout<<"You rolled a "<<roll<<endl;
               player=process(turnTotal,roll,player,humanTotal,computerTotal);
          
              
              
               printScores(turnTotal,humanTotal,computerTotal);
              
               continue;
           }
           else if(YoN=='N')
           {
               player=changePlayer(player); ///switch player to Computer
               humanTotal+=turnTotal;
               turnTotal=0;
           }
       }   
       else
       cout<<endl;
       cout<<"It is now computer's turn"<<endl;
       cout<<endl;
       roll=rollDie();
       cout<<"Computer rolled a "<<roll<<endl;
       player=process(turnTotal,roll,player,humanTotal,computerTotal);
   }///while ends here
  
   ///check who is winner
   if(humanTotal>=80){
   cout<<"Congratulations! human won this round of Jeopardy Dice!"<<endl;
   }
   else{
   cout<<"Congratulations! computer won this round of Jeopardy Dice!"<<endl;
   }
}
int main()
{
   game();
   return 0;
}

Screen shots

please don't forget to hit the thumbs up button

Thank you :)

Add a comment
Know the answer?
Add Answer to:
can someone help me fix my jeopardy dice game I am having a hard time figuring...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • can someone help me fix my jeopardy game #include<iostream> #include<stdlib.h> using namespace std; int rollDie() {...

    can someone help me fix my jeopardy game #include<iostream> #include<stdlib.h> using namespace std; int rollDie() { return (rand() % 6+1); } void askYoNs(){ cout<<"Do you want to roll a dice (Y/N)?:"<<endl; } void printScores(int turnTotal,int humanTotal,int compTotal){ int player; int human; if(player==human){ cout<<"Your turn total is "<<turnTotal<<endl; } else{ cout<<"computer turn total is "<<turnTotal<<endl; } cout<<"computer: "<<compTotal<<endl; cout<<"human: "<<humanTotal<<endl; cout<<endl; } int human; int changePlayer(int player){ if(player==human) return 1; return human; } int process(int& turnTotal,int roll,int curr_player,int& humanTotal,int& computerTotal){ if(roll==2...

  • can someone help me with this C++ problem write your game() function and 3+ functions that...

    can someone help me with this C++ problem write your game() function and 3+ functions that simulate the game of Jeopardy Dice according to the following game mechanics and specifications. Game Mechanics There are two players: the user and the computer, who alternate turns until one of them reaches 80 points or higher. The user is always the first player and starts the game. If any player reaches 80 points or more at the end of their turn, the game...

  • Two player Dice game In C++ The game of ancient game of horse, not the basketball...

    Two player Dice game In C++ The game of ancient game of horse, not the basketball version, is a two player game in which the first player to reach a score of 100 wins. Players take alternating turns. On each player’s turn he/she rolls a six-sided dice. After each roll: a. If the player rolls a 3-6 then he/she can either Roll again or Hold. If the player holds then the player gets all of the points summed up during...

  • The game of Pig is a simple two-player dice game in which the first player to...

    The game of Pig is a simple two-player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn, a player rolls a six-sided die: If the player rolls a 1, then the player gets no new points and it becomes the other player’s turn. If the player rolls 2 through 6, then he or she can either ROLL AGAIN or HOLD:      At this point, the sum of all rolls...

  • The Rules of Pig Pig is a folk jeopardy dice game with simple rules: Two players...

    The Rules of Pig Pig is a folk jeopardy dice game with simple rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 (”pig”) is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player’s turn, the player is faced with two decisions: roll If the player rolls a 1: the player scores nothing and it becomes the...

  • For your final project you will incorporate all your knowledge of Java that you learned in this class by programming the game of PIG. The game of Pig is a very simple jeopardy dice game in which two p...

    For your final project you will incorporate all your knowledge of Java that you learned in this class by programming the game of PIG. The game of Pig is a very simple jeopardy dice game in which two players race to reach 100 points. Each turn, a player 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 total). At any time during a player's turn,...

  • java thank you! Pig is a traditional dice jeopardy game. Players take turns, starting with a...

    java thank you! Pig is a traditional dice jeopardy game. Players take turns, starting with a randomly-chosen player. On their turn a player rolls a single 6-sided die 1 or more times. After each roll, the player has a choice: hold Stop rolling and add the total of al numbers rolled this turn to their score, or roll Roll the die again. If the player rolls a 1, their turn ends and they score 0 for the turn. Points scored...

  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • Java Listed below is code to play a guessing game. In the game, two players attempt...

    Java Listed below is code to play a guessing game. In the game, two players attempt to guess a number. Your task is to extend the program with objects that represent either a human player or a computer player. boolean checkForWin (int guess, int answer) { System.out.println("You guessed" + guess +"."); if (answer == guess) { System.out.println( "You're right! You win!") ; return true; } else if (answer < guess) System.out.println ("Your guess is too high.") ; else System.out.println ("Your...

  • I need help figuring out how to code this in C++ in Visual Studio. Problem Statement:...

    I need help figuring out how to code this in C++ in Visual Studio. Problem Statement: Open the rule document for the game LCR Rules Dice Game. Develop the code, use commenting to describe your code and practice debugging if you run into errors. Submit source code. Use the document to write rules for the user on how to play the game in a text file. Then, using the information from the resource articles, create a program that will read...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT