1. If maximum is over the limit, then the minimum is over the limit too. You have to decide whether it is sufficient for maximum to exceed the limit, or do you require each days minimum to exceed the limit. In either case you need only one test.
2. It does look like that you read data into array(s), but you don't hint that you need those arrays anywhere else and you do use the values as they come. In other words, there is no apparent reason to use arrays at all. It would be different, if you would read data to array in one loop and do computations is separate loop.
3. What if days 42--46 are hot? Will you print:
Days: 42, 43, 44
Days: 43, 44, 45
Days: 44, 45, 46
4. What if you keep track of count of consecutive hot days?
hots=0 at start
IF day is hot, THEN ++hots, ELSE hots=0
IF 2<hots, THEN day-2, day-1, day were hot
A couple of comments first. The variable "n" could use a better name the reflects the number it holds. It makes the program easier to read and for others to better understand.
The two if statements inside do not seem to work well together. I am thinking they should be in separate for loops or maybe need to be done differently.
To the if statements you are checking only one day when you should be checking three days like:
if(minimum[x] > n && minimum[x + 1] > n && minimum[x + 2] > n).
After that I would try making the second if statement an else if statement and set it up like the first if.
Line 18 needs to be in an if statement or it will print in each iteration of the loop even if it should not. For the actual statement it would be
<day1 + 1<<", "<<day1 + 2 .... There is no real need for the "day2" and "day3" variables. the "+1" on "day1" is because the array is zero based, so element zero would correspond to day 1. You are not wanting to print out the position in the array, but the day of the year.
I noticed that the arrays are filled at the beginning of the loop. This will not work because you will be trying to check elements of the array that do not yet exist. This input needs to be done before this for loop so that the arrays are filled before used.
Hope that helps,
Last edited on
just curious if there is any way I could download the data file that you are using.