I'm doing a project for school and I'm having difficulty getting the average of two averages, using arrays. I have to get the average of high temperatures for a year, the average for low temperatures for a year, and then find the average of those average. We used 366 days a year, which is 732 added for both low and high. Here's the code I have now:
int DailyTemps::get_avg()
{
double avg_temp_hi, avg_temp_lo, total_avg;
for(int i = 1; i < num_days; i++)
{
avg_temp_hi = temps_hi[i] + avg_temp_hi;
}
for(int i = 1; i < num_days; i++)
{
avg_temp_lo = temps_lo[i] + avg_temp_lo;
}
total_avg = (avg_temp_hi + avg_temp_lo) / (732);
return(total_avg);
}
The first time I run the program it outputs
the avg high daily temperature last year was -2147483648
When the menu repeats and I select the option for average, it outputs:
the avg high daily temperature last year was 50
What is wrong with this code?