/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
using namespace std;
int main(void)
{
int i;
int limit;
int day[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int high[10], low[10];
printf("---===IPC Temperature Analyzer V2.0===---\n");
printf("Please enter the number of days between 3 and 10, inclusive: ");
scanf("%d", &limit);
while (limit <= 2 || limit >= 11) {
printf("Invalid entry, please enter a number between 3 and 10, inclusive: ");
scanf("%d", &limit);
}
for (i = 0; i < limit; i++) {
printf("Day %d - High: ", day[i]);
scanf("%d", &high[i]);
printf("Day %d - Low: ", day[i]);
scanf("%d", &low[i]);
}
printf("\nDay Hi Low\n");
for (i = 0; i < limit; i++) {
printf("%d %d %d\n", day[i], high[i], low[i]);
}
int max = 0;
int min = 0;
for (i = 0; i < limit; i++) {
if (high[max] < high[i])
max = i;
if (low[min] > low[i]) //ERR: you put "<" instead of ">"
min = i;
}
printf("\nHighest temperature was: %d on day %d", high[max], day[max]);
printf("\nLowest temperature was: %d on day %d ", low[min], day[min]);
int n;
while(n>=0)
{
printf("\nEnter a number between 1 and %d to see the average temperature for the entered number of days, enter a negative number to exit",limit);
scanf("%d", &n);
//ERR: I just added another statment in order to deal with n=0
while (n > limit || n==0 ) {
printf("Invalid entry, please enter a number between 1 and %d inclusive: ",limit);
scanf("%d", &n);
}
//calculating the average
float sum=0;
float avg;
for (i = 0; i < n; i++) {
sum+=(high[i]+low[i])/2; //ERR: dont forget the brackets!!! you wrote: high[i]+low[i]/2 which is wrong!
}
avg= (float) (sum/n); //ERR: don't forget the casting
printf("The average temperature up to day %d is: %f", n, avg);
}
printf("Goodbye!\n");
return 0;
}