Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an excel vba program that simulates the rolling of two dice. The output fr

ID: 3833125 • Letter: W

Question

Write an excel vba program that simulates the rolling of two dice. The output from this program is shown below. The user enters the total number of simulated rolls into the spreadsheet (in the indicated cell). In the figure below, there will be 100,000 simulated rolls. When the ‘Run’ button is pressed, your program will simulate the user entered number die rolls. The outcome of each roll is an integer in the range of 2 to 12. For each roll, the outcome (2 – 12) is recorded and the total number of times for each outcome is stored in an array. This data is output to the ‘Number’ column. For instance, the number 7 results in 17941 of the 100,000 rolls in the example below. The ‘pct’ column records the percentage that each number results (of which 7 was 17.94% of the 100,000 rolls. The percentage data is stored in another array. Once the rolls have been simulated and the Number and Percentage arrays have been filled, output the data to the spreadsheet in the manner displayed in the figure. The ‘Clear button will clear the data from the ‘Number’ and ‘pct’. Column headings as well as the data in the Roll column does not need to be input by the program

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;

double total_Array[11];
double expected_Array[11];
double actual_Array[11];
int seed;

void initialization_of_Array()
{
for (int counter=0; counter < 12; counter++)
{
total_Array[counter] = 0;
expected_Array[counter] = 0;
actual_Array[counter] = 0;
}
}

void show_heading_line()
{
cout << setw(5) << "Sum"
<< setw(10) << "Total"
<< setw(17) << "Expected"
<< setw(16) << "Actual"
<< endl;
}

void show_Data_Results_line(int sum, int total, double expected, double actual)
{
cout << setw(5) << sum
<< setw(10) << total
<< setw(16) << expected << "%"
<< setw(15) << actual << "%"
<< endl;
}

void calculation_of_total()
{
int die_1, die_2;
for (int counter = 1; counter <= 3600; counter++)
{
die_1 = 1 + rand() % 6;
die_2 = 1 + rand() % 6;
total_Array[((die_1 + die_2)-2)]++;
}
}

void calculation_of_expect()
{

}

void calculation_of_actual()
{
for (int counter = 0; counter < 11; counter++)
{
actual_Array[counter] = (total_Array[counter] / 3600.0) * 100.0;
}
}

void rollDice_Operation()
{
calculation_of_total();
calculation_of_expect();
calculation_of_actual();
}

void print_Result()
{
show_heading_line();
for (int counter = 0; counter <= 10; counter++)
{
show_Data_Results_line((counter+2), total_Array[counter], 1, actual_Array[counter]);
}
}

void Q2_main()
{
cout << setprecision(3) << fixed;
initialization_of_Array();
cout << "Please enter the seed : ";
cin >> seed;
srand(seed);
rollDice_Operation();
print_Result();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote