הערה (קובץ קוד)
קובץ זה הוא קובץ קוד מסוג C.
#include <stdio.h>
int main(void)
{
int totalNumOfTemp = 0;
double maxTemp = 0, minTemp = 0, sumTotal = 0, weeklySumTemp = 0, userInput;
while (scanf("%lf", &userInput) > 0)
{
// checking for new min/max temps
if (userInput < minTemp || minTemp == 0)
{
minTemp = userInput;
}
if (userInput > maxTemp)
{
maxTemp = userInput;
}
sumTotal += userInput;
weeklySumTemp += userInput;
totalNumOfTemp++;
if (totalNumOfTemp % 7 == 0)
{
const int weekNumber = totalNumOfTemp / 7;
printf("Week %d average: %.2lf\n", weekNumber, (weeklySumTemp / 7));
weeklySumTemp = 0;
}
}
// printing the final points of information
printf("Max temp: %.2lf\n", maxTemp);
printf("Min temp: %.2lf\n", minTemp);
double avgTemp = sumTotal / totalNumOfTemp;
if (avgTemp < 15)
{
printf("Error in input!\n");
}
else
{
printf("Average temp: %.2lf\n", avgTemp);
}
return 0;
}