Meu codigo nao soma os valores inseridos, o computador sempre tira a media dos dois ultimos numeros inseridos. Como acertar isso?
#include <stdio.h>
#define NUMS 3
int main(void){
int high;
int low;
int i;
float totalHigh = 0;
float totalLow = 0;
double average;
printf("---=== IPC Temperature Analyzer ===---\n");
for (i = 0; i < NUMS; ++i) {
float totalHigh = 0;
float totalLow = 0;
do{
printf("Enter the high value for day %d: \n", i+1);
scanf("%d", &high);
printf("Enter the low value for day %d: \n", i+1);
scanf("%d", &low);
if ((high > 40) || (low < -40) || (high < low)){
printf ("Incorrect values, temperatures must be in the range -40 to 40, high must be greater than low.\n");
}
} while((high > 40) || (low < -40) || (high < low));
totalHigh = totalHigh + high;
totalLow = totalLow + low;
}
average = ((totalHigh + totalLow) / NUMS) / 2;
printf("The average (mean) temperature was: %.2f\n", average);
return 0;
}