- In this challenge your objective is to improve
on the previous challenge you worked on
with the bar charts.
The main objective at the higher level
is to continue to learn how to solve problems
using loops and arrays.
And creatively integrate multiple concepts
we've covered so far in this course.
Specifically for this problem,
look at the same challenge as in Chapter 09_06.
Revisit the bar chart program
and if you haven't been able to look at it yet, please do.
Generate the random data set
that's an improvement over the previous program.
The data set should consist of integer numbers
in a given range.
For example, between zero and 50.
I will show you how to generate random data numbers
in a minute.
Then you will store the data generated into an array
called dataSet [].
You should have a function that generates the data set
and populates the array.
Then in the function that creates the bar chart
read the data stored in the data set,
meaning in the array
and print it in the same manner you did it
for the previous challenge.
Let's see how we generate random numbers in C.
First of all, place the following #include in the header.
I will explain in a minute why.
Second, call this function srand from the function
that you use to generate the data to populate the array.
Finally, in the loop in which you assign
a data value to each data set element
of the data set array, insert this line.
This will create a random number between zero and 49.
How does this work?
The C compiler has a built in random number generator.
It's not really a random number,
but it's using the mathematical formula
to generate a series that has all the attributes
of random numbers.
In order for those numbers to be different each time
we need to initialize the series
with a unique number.
That unique number is the current time in millisecond.
Since the clock moves continuously,
and time never repeats itself,
by accessing the current time in milliseconds
we are able to ensure that each time you run the program
the random generated sequence
will start at a different place and therefore
will be different.
There is much more to that
but this is sufficient for the purpose of this exercise
and for the scope of this particular introductory
level course in C.
The random function rand,
it's another built in function in C
that together with the modal function, 50
allows you to generate integer numbers
between zero and 49.
We estimate that the total time for completion
of this exercise is about 30 minutes.
Good luck.