Answer to Question #212376 in C++ for youbo

Question #212376

- Roll a six-sided die 6000 times. Then show the output frequency elements 1-6 in

tabular format. Use the following


srand( time( 0 ) ); // seed random-number generator

face = 1 + rand() % 6 ; // generate rand face from 1:6

create B[face] list to count the number of occurrence the faces 1 -6,

Show the output as

Face Frequency

1 1003

2 1004

3 999

4 980

5 1013

6 1001


1
Expert's answer
2021-07-01T04:19:18-0400
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;


int main() {
    int B[7] = {0};     // B[0] doesn't used
    srand(time(0)); // seed random-number generator 


    for (int i=0; i<6000; i++) {
        int face = 1 + rand()%6; // generate rand face from 1:6
        B[face]++;
    }
    cout << "Face Frequency" << endl;
    for (int i=1; i<=6; i++) {
        cout << i << " " << B[i] << endl;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS