Member Avatar for sgame144

I am trying to write this program that requires the following for C++:

Write a c++ program to simulate the roll of a die. In principle, each of six possible outcomes is equally likely.
-The program will prompt the usesr to enter the # of times the die is to be thrown. That # of random #'s in the range 1-6 will be generated and the frequency of occurance of each is to be recorded.
-The program will produce the following output:
--A statement of the number of times the die was thrown
--A well designed and formatted table with the following column headings:
Value Number of Occurrences Percent of Occurrences

The output will go down from the headings ^ and be centered.
Test data: 2 different number of throws: 1000 and 5000

SO, i can pretty much do everything, but whats keeping me stuck is the part of how the frequency of occurrence of each is to be recorded and making the table. Can anyone help, alot or even just a little?

Well you could use a simple array to count how many times each number occurs.

int nums[= = {0,0,0,0,0,0};
nums[roll()-1] += 1;

You get the idea, thats assuming roll() returns a number between 1&6

Member Avatar for sgame144

true, thanks. ill try it out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.