Question

// This program creates a simulated player who takes one turn in the // Pig dice...


// This program creates a simulated player who takes one turn in the
// Pig dice game. The simulated player keeps rolling the die until
// the total for the turn is 20 or greater, or until a 1 is rolled.
// If a 1 is rolled, the player's score for the turn is 0. Otherwise
// the player's score is the sum of the rolls for the turn.
//
/////////////////////////////////////////////////////////////////////

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

using namespace std;

int randNumGen(int upper, int lower);   // function prototype

int main()
{
int roll; // The value of the die roll
int total_turn = 0; // Player's score for this turn

// Seed the random number generator
srand(static_cast<int> (time(NULL)));

  
/////////////////////////////////////////
// Start of your code

  
// Use a while loop to roll the die until the total turn number is
// 20 or greater, or until a 1 is rolled. if a 1 is rolled the
// player gets a 0 for the turn.
// Call function randNumGen() to generate a number within the range 1..6

   // to simulate the rolling of the die
  
  
  
  
  
  
//output the number of points the simulated player got for the turn.

  
// End of your code
/////////////////////////////////////////

system("pause");
return 0;

}//close main()

// function definition
int randNumGen(int upper, int lower)   // function heading
{                                       // function body
   return (rand() % (upper - lower + 1)) + lower;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
// This program creates a simulated player who takes one turn in the
// Pig dice game. The simulated player keeps rolling the die until
// the total for the turn is 20 or greater, or until a 1 is rolled.
// If a 1 is rolled, the player's score for the turn is 0. Otherwise
// the player's score is the sum of the rolls for the turn.
//
/////////////////////////////////////////////////////////////////////

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

using namespace std;

int randNumGen(int upper, int lower);   // function prototype

int main() {
    int roll; // The value of the die roll
    int total_turn = 0; // Player's score for this turn

// Seed the random number generator
    srand(static_cast<int> (time(NULL)));


/////////////////////////////////////////
// Start of your code


// Use a while loop to roll the die until the total turn number is
// 20 or greater, or until a 1 is rolled. if a 1 is rolled the
// player gets a 0 for the turn.
// Call function randNumGen() to generate a number within the range 1..6
// to simulate the rolling of the die
    while (total_turn < 20 && (roll = randNumGen(1, 6)) != 1) {
        total_turn += roll;
    }
    if (roll == 1) {
        total_turn = 0;
    }
//output the number of points the simulated player got for the turn.
    cout << "Total number of points = " << total_turn << endl;
    
// End of your code
/////////////////////////////////////////

    system("pause");
    return 0;

}//close main()

// function definition
int randNumGen(int upper, int lower)   // function heading
{                                       // function body
    return (rand() % (upper - lower + 1)) + lower;
}

Add a comment
Know the answer?
Add Answer to:
// This program creates a simulated player who takes one turn in the // Pig dice...
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
  • please write the following program in Java PIG is one of a family of games called...

    please write the following program in Java PIG is one of a family of games called jeopardy dice games, since a player's main decision after each roll is whether to jeopardize previous gains by trying for potentially even greater gains. In PIG, all players start with ZERO points, and each turn involves rolling a die to earn points. The first player to earn 100 points or more total shouts "PIG!" and wins the game. On their turn, a player does...

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

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

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

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

  • #2 New Turn Rules A frustrating aspect of programming on a project with other programmers is the ...

    #2 New Turn Rules A frustrating aspect of programming on a project with other programmers is the fact that everyone solves problems in different ways. Just when you think you know which way things are headed, someone throws a snag in your design. Objects needed: Die Attributes Current value of the die Actions roll the die DiceSet Attributes An array of six Die The number of dice available to roll. When this number reaches 0, it is reset to 6....

  • Assignment 2 – The two player game of Poaka The game of Poaka is a dice...

    Assignment 2 – The two player game of Poaka The game of Poaka is a dice game played by two players. Each player takes turns at rolling the dice. At each turn, the player repeatedly rolls a dice until either the player rolls a 1 (in which case the player scores 0 for their turn) or the player chooses to end their turn (in which case the player scores the total of all their dice rolls). At any time during...

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

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

  • In Yahtzee, 5 standard dice are rolled up to three times on a given turn. A...

    In Yahtzee, 5 standard dice are rolled up to three times on a given turn. A player can choose to save anywhere from 0 - 5 of the dice between rolls 1 and 2 and between rolls 2 and 3, meaning that the player can set aside certain dice before rolling the remaining dice if they choose to do so. Suppose that a given player does not take advantage of saving die rolls and instead rolls all 5 dice each...

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