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 will 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 4 points) 1. Flowchart of your program. 2. Printout of your C+program with a heading comment (Do not forget to 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 libraries

#include <iostream>

#include <stdlib.h>

#include <iomanip>

using namespace std;

/*Function prototype*/

int twoDice();

//Define a main method

int main()

{

     //Declare arrays

     int sum[100], a[100], b[100];

     //Call twoDice() to get first number

     int A = twoDice();

     //Call twoDice() to get second number

     int B = twoDice();

     //Compute sum

     int C = A + B;

     //Display values

     cout<<\"A = \"<<A<<\" \"<<\"B = \"<<B<<\" \"<<\"Sum is \"<<C<<endl;

     //Loop until 100

     for(int li=0;li<100;li++)

     {

//Call twoDice() to get first number and store in array

          a[li] = twoDice();

//Call twoDice() to get second number and store in array

          b[li] = twoDice();

          //Store sum in array

          sum[li] = a[li]+b[li];

     }

     //Set heading

     cout<<\"a\"<<setw(8)<<\"b\"<<setw(25)<<\"sum\"<<endl;

     //Loop until 100

     for(int li=0;li<100;li++)

     {

          //Dsiplay values

          cout<<a[li]<<setw(8)<<b[li]<<setw(25)<<sum[li]<<endl;

     }

     //Pause console window

     system(\"pause\");

     //Return 0

     return 0;

}

//Define function twoDice()

int twoDice()

{

     //Call rand() function.

     int num1 = rand() % 6 + 1;

     //Return number

     return num1;

}

Sample Output:

A = 6 B = 6 Sum is 12

a       b                      sum

5       5                       10

6       5                       11

1       1                        2

5       3                        8

6       6                       12

2       4                        6

2       6                        8

2       3                        5

4       1                        5

4       1                        5

3       4                        7

5       5                       10

4       3                        7

3       6                        9

6       1                        7

6       1                       7

4       5                        9

6       2                        8

2       1                        3

6       4                       10

3       4                        7

4       3                        7

4       2                        6

6       5                       11

6       3                        9

5       4                        9

4       2                        6

6       4                       10

2       5                        7

5       6                       11

3       1                        4

1       5                        6

5       3                        8

5       5                       10

3       4                        7

3       4                        7

5       3                        8

1       4                        5

4       3                        7

4       6                       10

1       5                        6

1       3                        4

5       3                        8

6       5                       11

1       4                       5

3       2                        5

6       5                       11

3       1                        4

4       6                       10

4       6                       10

2       1                        3

1       1                        2

4       3                        7

6       1                        7

6       6                       12

3       5                        8

1       4                        5

6       4                       10

4       1                        5

5       1                        6

6       1                        7

6       6                       12

4       5                        9

6       5                       11

3       5                        8

4       5                        9

5       5                       10

4       6                       10

2       4                        6

2       6                        8

4       4                        8

6       6                       12

2       3                        5

6       1                       7

3       5                        8

3       5                        8

4       3                        7

1       6                        7

1       6                        7

5       6                       11

1       6                        7

3       4                        7

2       4                        6

3       3                        6

2       3                        5

3       5                        8

1       4                        5

1       4                        5

1       5                        6

2       1                        3

6       2                        8

1       3                        4

1       3                        4

2       6                        8

3       2                        5

1       2                        3

6       4                       10

1       6                        7

2       5                        7

6       3                        9

Press any key to continue . . .

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site