This is a problem from Computational Methods using VBA in excel and it deals wit
ID: 3675384 • Letter: T
Question
This is a problem from Computational Methods using VBA in excel and it deals with Arrays.
Write a 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 16627 of the 100,000 rolls in the example below. The "pfX' column records the percentage that each number results (of which 7 was 16.63% 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 #include #include int main(void) { int number1,number2,roll,number=0,i; int frequency[13]={0}; int pct[ 13 ] = { 0, 0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1}; srand(time(NULL)); for (i = 0; i < 100000; i++) { roll=0; number1=1+rand()%6; number2=1+rand()%6; roll=number1+number2; frequency[roll]++; } for (i = 0; i < 13; i++) { number+=frequency[i]; } printf("roll number pct Actual "); for (i = 2; i < 13; i++) { printf("%2d %8d %f %9f ",i,frequency[i], 100.0*pct[i]/100100*(double)frequency[i]/total ); } getch(); return 0; } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.