Question

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 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

#include<iostream>
#include<stdlib.h>
#define USER 0 /// 0 means user
using namespace std;

/// function to ask optons to USER
void askOptions()
{
cout<<" Select options";
cout<<" 1.Continue Rolling";
cout<<" 2.Hold ";
}

///function to roll die
/// returns number betweeen 1 to 6
int rollDie()
{
return (rand() % 6+1);
}

///function that takes arguments and prints scores
void printScores(int turnTotal,int userTotal,int compTotal)
{
cout<<" turnTotal= "<<turnTotal;
cout<<" userTotal="<<userTotal;
cout<<" CompTotal="<<compTotal;
}

///to switch player
int changePlayer(int player)
{
if(player==USER)
return 1;
return USER;
}

/// function to process current die points
/// turnTotal ,userTotal and computerTotal are referrence args whose contents can be chnaged within the function
int process(int& turnTotal,int points,int curr_player,int& userTotal,int& computerTotal)
{
if(points==2 || points==5) ///turn ends & turnTotal=0
{
///switch player
curr_player=changePlayer(curr_player);
turnTotal=0;
printScores(turnTotal,userTotal,computerTotal);
}
else if(points==4) ///turn ends & turnTotal=15
{
turnTotal=15;
///switch player
if(curr_player==USER)
userTotal+=turnTotal;
else
computerTotal+=turnTotal;
curr_player=changePlayer(curr_player);
turnTotal=0;
printScores(turnTotal,userTotal,computerTotal);

}
else{ ///points = 1 3 6
turnTotal+=points;
cout<<" TurnTotal ="<<turnTotal;
}
///if computer turnTotal becomes >=10
///then switch player
if(curr_player!=USER && turnTotal >=10 )
{
computerTotal+=turnTotal;
curr_player=changePlayer(curr_player);
turnTotal=0;
printScores(turnTotal,userTotal,computerTotal);
cout<<" ************************************ ";
}

return curr_player;
}

void game()
{
int player=USER;
int userTotal=0;
int computerTotal=0;
int turnTotal=0;


while(userTotal<=80 && computerTotal<=80)
{
int points=0;
if(player==USER)
{
cout<<" Player = USER ";
int option;
askOptions();
cin>>option;
if(option==2) ///hold
{
userTotal+=turnTotal;
player=1; ///switch player to Computer
printScores(turnTotal,userTotal,computerTotal);
turnTotal=0;
cout<<" ************************************ ";
continue;
}
}
else
cout<<" Player =COMP ";
points=rollDie();
cout<<" You score ="<<points;
player=process(turnTotal,points,player,userTotal,computerTotal);
cout<<" ************************************ ";

}///while ends here

///check who is winner
if(userTotal>=80)
{
cout<<" ******************************* ";
cout<<" !!! USER WON !!! ";
}
else{

cout<<" ******************************* ";
cout<<" !!! COMP WON !!! ";

}


}


int main()
{
game();

return 0;
}

Add a comment
Know the answer?
Add Answer to:
can someone help me with this C++ problem write your game() function and 3+ functions that...
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 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...

  • 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...

  • 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...

  • python code( using functions please)! Rules of the game: - This game requires a dice. The...

    python code( using functions please)! Rules of the game: - This game requires a dice. The goal of the game is to collect the correct number of coins to create a dollar. Players take coins based on a roll of the dice. The numbers on the dice correlate to the coin values as follows:  1—penny  2—nickel  3—dime  4—quarter  5— ( pick a random card from 1 to 4): o 1 = penny o 2 =...

  • C++ Homework: This will be the first in a series of assignments to create a game...

    C++ Homework: This will be the first in a series of assignments to create a game called Zilch. In this assignment, you will create the basic structure of the program and demonstrate the ability to create programs with multiple files. It should serve as a refresher in the basics of C++ programming, especially in the handling of arrays. The initial assignments only establish a rough outline of the game. We will be adding the rules that make the game more...

  • 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...

  • C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an...

    C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an elimination dice game. It can be played by any number of players, but it is ideal to have three or more players. Wild, Wild, West! Requires the use of two dice. At the start of the game, each player receives a paper that will track the number of lives that player has. Each player starts the game with 6 lives. In the first round,...

  • Hello, Could you please help me code this program in Java? It is important that all...

    Hello, Could you please help me code this program in Java? It is important that all rules are carefully followed. Using the PairOfDice class from PP 4.9, design and implement a class to play a game called Pig. In this game, the user competes against the computer. On each turn, the current player rolls a pair of dice and accumulates points. The goal is to reach 100 points before your opponent does. If, on any turn, the player rolls a...

  • 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...

  • 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