int find_largest (int data[], int n) { int i, largest; // start of by assuming that the first value is our largest value. // this is cleaner than using -INT_MAX (which does work) and much // better than using an arbitrary value like zero (which doesn't work // if all of the values are less than the value chosen) largest = data[0]; // now consider all of the remaining values (note: i starts at 1) for (i = 1; i < n; i++) { if (data[i] > largest) { largest = data[i]; // we have a new champion } } return largest; } void analyze_temperatures (double temperatures[], int years, int &big_ups, int &big_downs) { int i; double increase; big_ups = big_downs = 0; // nothing seen so far for (i = 0; i < years - 1; i++) { // the following will cause a problem if temperatures[i] is zero, // and will produce a nonsense value if temperture[i] is negative. // this was a flaw in the question (in retrospect I should have // specfied Kelvin temperatures) and the issue is ignored here. instead // it is simply assumed that all temperatures are greater than zero. // note the order of operations and the use of 100.0 instead of 100 // (there is a danger here of getting integer division and this isn't // what is called for). increase = ((temperatures[i + 1] - temperatures[i]) * 100.0) / temperatures[i]; if (increase >= 2.0) { big_ups++; } else if (increase <= -2.0) { big_downs--; } } }