Don't understand teachers instructions

So my professor recently gave us this assignment and I don't understand a lot of it because it deals with rand() and srand() which my professor didn't cover that well. The instructions are as follows:

1. Write a function that will generate 40 random integers between 1 and 25. Recall that the rand() function will be helpful here. Output them in 5 columns.

2. Determine and output the average value of the 40 numbers. The average value should be output (just one time) with 3 digits to the right of the decimal point.

3. Determine and output the least and the greatest value of the 40 numbers. Output the number of times the least and the greatest value occur (e.g. "2 was least, and it occurred 3 times, 49 was greatest, and it occurred 2 times")

4. Output a horizontal version of a histogram to illustrate the distribution of the numbers. An example of one is provided below:

1-5: *******
6-10: ********
11-15: **********
16-20: ********
21-25: ********


I know how to generate the random numbers but what I'm getting stuck on is how to output them in five columns because I think he wants us to do the 1-5 thing but display the numbers it came up with.

I also don't get how to do 3 & 4.

I don't expect you to do the assignment for me I'm just looking for a nudge in the right direction.
#3: Record the smallest and largest value generated in seperate variables. You just need to perform a comparison on each value as it's generated.

#4: Typical binned histogram. Each group of numbers represents a single 'bin' which can be a simple counter variable. As you generate each random number, increment the counter for the bin that number falls in. At the end, output an * for each count in each bin to generate your histogram.
You could just use a map<int,int> that stores the random number as a key and a count of its occurrences. Then it's already sorted and you can extract the smallest and largest numbers and their counts easily. At that point, the histogram will be easy, too.
Topic archived. No new replies allowed.