Hello,
I am trying to write a frequency program that will represent a bar diagram (in console code).
The problem is i have no idea how exactly to caculate this frequency or how do i exactly then give the bars different heights according to there frequency (trough calculation).
The frequency height is capped at 21. (meaning the bars go from 1 to 21, so the max bar height would be for example 21 stars(* as display sign for the bar itself).
A calculation i have so far (although not sure if correct) for frequency:
This array takes the random values generated:
for (int j = 0; j < T.Length; j++)
{
T[j] = (MaxHeight* T[j]) / Ber.GreatestElement(T);
Console.Write("{0,7}", T[j]);
}
This results in values between 0 and 21 --> Based on the values my bars should give a certain height compared to all the other frequency values. (for example 8000 could have 21 in height where 39 could have 1).
To represent this diagram i used 2 for loops to display height and width (keep in mind i only wish to use Using System; to keep it to the "basics").
for (int height= 1; height<= 21; height++)
{
for (int width= 0; width<= 10; width++)
{
if(...??)
{
Console.Write("{0,7}", bar); // string bar= ("*");
}
else
{
Console.Write("{0,7}", empty);
}
}
Console.WriteLine();
}
So so far i have a entire field filled with * and the random values generated along with their frequency value (although i have no idea if the freq value is properly calculated).
I assume i need a if (.....) in the second for but i cannot seem to get further then this.
Thanks in advance!