Question

This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the...

This is for C++

#include <random>

#include <iostream>

#include <ctime>

using namespace std;

/*

In the game of craps, a shooter rolls 2 dice and adds the dots on the upper most

faces of

the dice.

7 or 11 on the first roll wins,

2, 3, or 12 on the first roll loses,

andthing else is call the point and the player rolls again

The following program fragment uses 1-way if statements simulate the 1st roll of

the dice.

Replace the 1-way if statements with multi-way if statements with compound

conditions. Your

solution should have only 1 return statement.

*/

int main()

{

//int seed = 0;

int seed = (int)time(nullptr);

default_random_engine e(seed);

uniform_int_distribution<int> u(1, 6);

int die1 = u(e);

int die2 = u(e);

int sum = die1 + die2;

cout << "You rolled " << sum << " = " << die1 << " + " << die2 << endl;

if (sum == 2)

{

cout << "you lose" << endl;

return 0;

}

if (sum == 3)

{

cout << "you lose" << endl;

return 0;

}

if (sum == 12)

{

cout << "you lose" << endl;

return 0;

}

if (sum == 7)

{

cout << "you win" << endl;

return 0;

}

if (sum == 11)

{

cout << "you win" << endl;

return 0;

}

cout << "roll again" << endl;

return 0;

}

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

If you have any doubts, please give me comment...

#include <random>

#include <iostream>

#include <ctime>

using namespace std;

/*

In the game of craps, a shooter rolls 2 dice and adds the dots on the upper most faces of the dice.

7 or 11 on the first roll wins,

2, 3, or 12 on the first roll loses,

andthing else is call the point and the player rolls again

The following program fragment uses 1-way if statements simulate the 1st roll of the dice.

Replace the 1-way if statements with multi-way if statements with compound conditions. Your solution should have only 1 return statement.

*/

int main()

{

//int seed = 0;

int seed = (int)time(nullptr);

default_random_engine e(seed);

uniform_int_distribution<int> u(1, 6);

int die1 = u(e);

int die2 = u(e);

int sum = die1 + die2;

cout << "You rolled " << sum << " = " << die1 << " + " << die2 << endl;

if (sum == 2 || sum==3 || sum==12)

cout << "you lose" << endl;

else if (sum == 7 || sum == 11)

cout << "you win" << endl;

else

cout << "roll again" << endl;

return 0;

}

Add a comment
Know the answer?
Add Answer to:
This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the...
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
  • Write a c++ program that simulates a million of games in craps. I am having a...

    Write a c++ program that simulates a million of games in craps. I am having a trouble getting to loop a million of times. I am trying to use a const for a million. This is the code so far. #include <iostream> #include <cstdlib>// contains prototypes for functions srand and rand #include <ctime>// contains prototype for function time #include <iomanip> using namespace std; int rollDice(); // rolls dice, calculates and displays sum void printstats(); int totroll = 0, games, point,...

  • Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN...

    Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN = 1; const int MAX = 10; int getRandom(int low, int high); int main() {    int random_num = 0; int player_num; int tries; int seed = static_cast<int>(time(0)); bool guessed = false;    srand(seed); // call the getRandom function below       tries = 4; while ( tries > 0 && !guessed ) { cout << "Enter a number within the range 1 to...

  • Required in C++ I'm asked to: Print a histogram in which the total number of times...

    Required in C++ I'm asked to: Print a histogram in which the total number of times the dice rolls equals each possible value is displayed by printing a character like * that number of times. Below is my current code. I am not allowed to use arrays or anything too advanced as I just started the class. I would really appreciate the help as I've been stuck on it for a while now. I can only get it to print...

  • Game of Craps C++ #include <iostream> using namespace std; void roll (int *); // using pointer...

    Game of Craps C++ #include <iostream> using namespace std; void roll (int *); // using pointer to catch the random variable value of two dicerolls at one time . //these global variable with static variable win use to operate the working of code . //static win, account because two times input given by user to add the diceroll with win number and //account (means balance of user) . static int account = 100; static int win = 0; int bet...

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

  • For C++ /* rewrite the following program to generate pairs of random number until the sum...

    For C++ /* rewrite the following program to generate pairs of random number until the sum of the digits of one random number equals the sum of the digits of the other random number. use only while loops in your solution. use only loop conditions to end the loop or escape the body of the loop. for example, 23( 5) 71( 8) 92(11) 6( 6) 13( 4) 99(18) 12( 3) 47(11) 63( 9) 18( 9) */ #include <cmath> #include <ctime>...

  • I'm trying to make a game of Craps in C++. This is how the teacher wants...

    I'm trying to make a game of Craps in C++. This is how the teacher wants the program to run. Player rolled: 6 + 4 = 10 The point is 10 Player rolled: 3 + 3 = 6 Player rolled: 6 + 3 = 9 Player rolled: 3 + 1 = 4 Player rolled: 3 + 4 = 7 You seven'd out and lost! Player rolled: 2 + 5 = 7 You won! Player rolled: 3 + 1 = 4...

  • Getting this error. [Error] expected ';' after class definition #include <iostream> #include <cstdlib> #include <ctime> #include...

    Getting this error. [Error] expected ';' after class definition #include <iostream> #include <cstdlib> #include <ctime> #include <conio.h> using namespace std; int sum=0; class Coin { int sideUp; public: Coin(int value) { toss(value); }; void toss(int value); } void Coin::toss(int value) { if(rand() %100<=50) { sum+=value; cout<<"\n You got a head. Value "<<value<<" added!!"; } else { cout<<"\n You got a tail. No value added"; } } int main() { int temp; cout<<"\n Quarter = 25 cents\n Dime = 10 cents...

  • #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0;...

    #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0; while(true) { cout << "Please enter a number between 1 and 11: "; cin >> number; if (number >= 1 && number <= 11) { cout << number << endl; sum = sum + number; //only add the sum when number is in range: 1-11, so add wthin this if case } else { cout << number << endl; cout << "Out of range;...

  • 4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std;...

    4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....

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