So what I have is two arrays each with different temperature readings. I have a low array that includes the low temperatures of the month and a high array that includes the high temperatures of the month. I got these variables by reading them in from a text file. My code for that looks like:
while ( !file.eof() )
{
file >> high[i] >> low[i];
i++;
}
I know the size of the array since it is the second line in the text file show below.
April 6, 2010
24
88 72
52 36
73 48
89 72
97 84
61 41
48 37
68 45
88 63
79 52
48 21
55 46
54 41
97 81
55 37
79 70
72 43
68 45
102 80
57 39
37 32
45 28
66 45
59 36
Now I have to get the counts from the temperatures and create a histogram that looks like the sample below. So if there are for example 2 temperatures greater or less than equal to 49 I would print two stars after the interval label.
< 0|
<= 9|
<=19|
<=29|*
<=39|
<=49|**
<=59|*
<=69|
<=79|*
<=89|
<=99|
>99|
I was thinking of combining the two arrays into one and looping through them but I the only way I currently know how to do this is by using a switch case or a giant if else block. Even if the there are no temperatures between 0 and 9 I would still have to print "<= 9|". I'm not sure how to create the count function without actually using a bunch of if-else's. Any ideas would be greatly appreciated.
I have this code for my count function right now that combines the two arrays but that is about it:
void count(float lowArr[], float highArr[], int num){
int size = num * 2, i = 0, j =0;
float *arr;
arr = new float[size];
for (i ; i < num; ++i)
{
arr[i] = lowArr[i];
}
for (j; j < num; ++j, ++i)
{
arr[i] = highArr[j];
}
}