+ 1

How to make this code shorter

Hello I am having trouble making my code shorter , if anyone can help me it would be great thanks. define _CRT_SECURE_NO_WARNINGS #include<stdio.h> int main(void) { int hightemp, lowtemp, highest = -41, lowest = 41, highestday, lowestday, sumhigh = 0, sumlow = 0; float averagehigh, averagelow, averagetemp; for (int i = 1; i <= 4; i++) { do{ printf("Enter the high value for day %d: ", i); scanf("%d", &hightemp); printf("Enter the low value for day %d: ", i); scanf("%d", &lowtemp); if (lowtemp > hightemp && lowtemp <= 40 && lowtemp >= -40 || lowtemp > hightemp && hightemp <= 40 && hightemp >= -40 || hightemp > 40 || lowtemp > 40 || hightemp < -40 || lowtemp < -40) { lowtemp = -43; hightemp = -45; printf("Incorrect values, temperature must be in the range between -40 to 40, high must be greater than low.\n"); } } while (lowtemp > hightemp && lowtemp <= 40 && lowtemp >= -40 || lowtemp > hightemp && hightemp <= 40 && hightemp >= -40 || hightemp > 40 || lowtemp > 40 || hightemp < -40 || lowtemp < -40); if (highest < hightemp) { highest = hightemp; highestday = i; } if (lowest > lowtemp) { lowest = lowtemp; lowestday = i; } sumhigh = sumhigh + hightemp; sumlow = sumlow + lowtemp; } averagehigh = (float)sumhigh / 4; averagelow = (float)sumlow / 4; averagetemp = (float)(sumhigh + sumlow) / 8; printf("The average LOW (mean) temperature was: %0.2f\n", averagelow); printf("The average HIGH (mean) temperature was: %0.2f\n", averagehigh); printf("The average (mean) temperature was: %0.2f\n", averagetemp); printf("The highest temperature was: %d, on day %d\n", highest, highestday); printf("The lowest temperature was: %d, on day %d\n", lowest, lowestday); return 0; }

3rd Oct 2019, 5:08 PM
Jonray
1 Réponse
0
What this code does ? then only i can make it short
7th Oct 2019, 6:06 AM
Programmer Raja
Programmer Raja - avatar