I have written a program that asks the user the input the high and low temperature over the course of four days. Following this, the program calculates the mean temperature using the inputs from all four days. Everything is working fine however, I need to have the program determine and output the greatest high temperature and the day it occurred on as well as the smallest low temperature and the day it occurred on. Here's my code so far
#include <stdio.h> #define NUMS 4 int main (void) { int high[NUMS]; int low[NUMS]; const int MAX = 40; const int MIN = -40; int totalhigh; int totallow; int sum; float avg; printf ("---===IPC Temperature Analyzer ===---\n"); printf ("Enter the high value for day 1: "); scanf ("%d", &high[0]); printf ("Enter the low value for day 1: "); scanf ("%d", &low[0]); while (high[0] > MAX || low[0] < MIN || high[0] < low[0]) { printf ("Incorrect values, temperatures must be in the range -40 to 40, high must be greater than low.\n"); printf ("Enter the high value for day 1: "); scanf ("%d", &high[0]); printf ("Enter the low value for day 1: "); scanf ("%d", &low[0]); } printf ("Enter the high value for day 2: "); scanf ("%d", &high[1]); printf ("Enter the low value for day 2: "); scanf ("%d", &low[1]); while (high[1] > MAX || low[1] < MIN || high[1] < low[1]) { printf ("Incorrect values, temperatures must be in the range -40 to 40, high must be greater than low.\n"); printf ("Enter the high value for day 2: "); scanf ("%d", &high[1]); printf ("Enter the low value for day 2: "); scanf ("%d", &low[1]); } printf ("Enter the high value for day 3: "); scanf ("%d", &high[2]); printf ("Enter the low value for day 3: "); scanf ("%d", &low[2]); } printf ("Enter the high value for day 4: "); scanf ("%d", &high[3]); printf ("Enter the low value for day 4: "); scanf ("%d", &low[3]); while (high[3] > MAX || low[3] < MIN || high[3] < low[3]) { printf ("Incorrect values, temperatures must be in the range -40 to 40, high must be greater than low.\n"); printf ("Enter the high value for day 4: "); scanf ("%d", &high[3]); printf ("Enter the low value for day 4: "); scanf ("%d", &low[3]); } totalhigh = high[0] + high[1] + high[2] + high[3]; totallow = low[0] + low[1] + low[2] + low[3]; sum = totalhigh + totallow; avg = sum/8.0; printf ("The average (mean) temperature was: %.2f\n", avg); if (high[0] > high[1] || high[0] > high[2] || high[0] > high[3]) { printf ("The highest temperature was %d, on day 1\n", high[0]); } else if (high[1] > high[0] || high[1] > high[2] || high[1] > high[3]) { printf ("The highest temperature was %d, on day 2\n", high[1]); } else if (high[2] > high[0] || high[2] > high[1] || high[2] > high[3]){ printf ("The highest temperature was %d, on day 3\n", high[2]); } else { printf ("The highest temperature was %d, on day 4\n", high[3]); } return 0; }
scanf("%d", &high[0]);simplyscanf("%d", high[0])'is enough as an array is like a pointer (I said like). For example,a = &a[0];