Requirements 1 Create a function that simulates a throw of t

Requirements: (1) Create a function that simulates a throw of two dice. Hint: Create a function (2) The number of throw wll be one million. Count the sum of two dice. Hint (3) The result must be well formatted. The number, and histogram associated that simulates a throw of a die, then invoke it twice and add them. Use a loop and a one dimensional array with the number of throws need to be shown. Onc in the example. Hint: Use formatting and loops. *represents 10 thousand Please Hand in 1. Flowchart of your program. 2. Printout of your C+program with a heading comment (Do not forget to (4 points) add comments within your program) Copy of a screenshot after your program is executed. (4 points) (2 points) 3. ELEN 1301-02 Programming Assignment #10 Name Student ID Due date :Your name Your student ID : November 3, 2016 Purpose of the program: Creating throwing two dice simulator. Output example: Press any key to continue . . . .

Solution

#include <iostream>

#include <ctime>

#include <cstdlib>

#include <iomanip>

using namespace std;

int dice1;

int dice2;

int sum_of_dice;

int point;

int number_of_wins;

int number_of_lose;

double probability_of_winning;

double probability_of_losing;

int number_of_times_played;

int main()

{

   

    srand(time(0));

   

    do

    {

        dice1 = rand() % 6 + 1;

        dice2 = rand() % 6 + 1;

       

        sum_of_dice = dice1 + dice2;

       

        if (sum_of_dice == 7 || sum_of_dice == 11)

        {

            cout << \"Congratulations you have won!\" << endl;

        }

        else if (sum_of_dice == 2 || sum_of_dice == 3 || sum_of_dice == 12)

        {

           cout << \"Better luck next time the house has one!\" << endl;

        }

        else (sum_of_dice == 4 || sum_of_dice == 5 || sum_of_dice == 6 || sum_of_dice == 8 || sum_of_dice == 9 || sum_of_dice == 10);

        {

            do {

                dice1 = rand() % 6 + 1;

                dice2 = rand() % 6 + 1;

                int sum2 = dice1 + dice2;

                if( sum2 == sum_of_dice )

                {

                    cout << \"Congratulations you have won!\" << endl;

                    break;

                } else if( sum2 == 7 )

                {

                    cout << \"Better luck next time the house has one!\" << endl;

                    break;

                }

            } while(true);

           

        }

       

    } while (++number_of_times_played != 1000000);

   

    number_of_wins = number_of_times_played - number_of_lose;

    number_of_lose = number_of_times_played - number_of_wins;      // It is now telling me that I have never lost.

    probability_of_winning = number_of_wins / 10000;

    probability_of_losing = number_of_lose / 10000;

   

    cout << \"Out of 1 million games you won: \" << number_of_wins << endl;

    cout << \"Out of 1 million games you lose: \" << number_of_lose << endl;

    cout << \"The probability for the Player to win is: \" << probability_of_winning << setw(2) << \"%\" << endl;

  cout << \"the probability for House to win is: \" << probability_of_losing << setw(2) << \"%\" << endl;

   

        return 0;

}//End Code!

 Requirements: (1) Create a function that simulates a throw of two dice. Hint: Create a function (2) The number of throw wll be one million. Count the sum of tw
 Requirements: (1) Create a function that simulates a throw of two dice. Hint: Create a function (2) The number of throw wll be one million. Count the sum of tw
 Requirements: (1) Create a function that simulates a throw of two dice. Hint: Create a function (2) The number of throw wll be one million. Count the sum of tw

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site