In: Computer Science
#define _CRT_SECURE_NO_WARNINGS
// Put your code below:
#include <stdio.h>
int main(void)
{
int day, hightemp[10], lowtemp[10], numbers, highesttemp,
highestday, lowesttemp, lowestday, numbers2 = 0, hightotal = 0,
lowtotal = 0, averageday = 0, numbers3;
double averagetemp;
printf("---=== IPC Temperature Calculator V2.0 ===---");
printf("\nPlease enter the number of days, between 3 and 10,
inclusive: ");
scanf("%d", &numbers);
if (numbers < 3 || numbers > 10)
{
printf("\nInvalid entry, please enter a number between 3 and 10,
inclusive: ");
scanf("%d", &numbers);
printf("\n");
}
while (numbers < 3 || numbers > 10);
for (day = 1; day <= numbers; day++)
{
printf("Day %d - High: ", day);
scanf("%d", &hightemp[day - 1]);
printf("Day %d - Low: ", day);
scanf("%d", &lowtemp[day - 1]);
if(highesttemp <= highesttemp[day - 1])
{
highesttemp = highesttemp[day - 1];
highesttemp = day;
}
if (lowesttemp >= lowesttemp[day - 1])
{
lowesttemp = lowesttemp[day - 1];
lowesttemp = day;
}
}
printf("\nDay Hi Low\n");
for (day = 1; day <= numbers; day++)
{
printf("%d %d %d\n", day, hightemp[day - 1], lowtemp[day - 1]);
}
printf("\nThe highest temperature was %d, on day %d\n", highesttemp, highestday);
printf("The lowest temperature was %d, on day %d\n", lowesttemp, lowestday);
while (numbers2 == 0)
{
printf("\nEnter a number between 1 and 5 to see average temperature
for the entered number of days, enter a negative number to exit: ",
numbers);
scanf("%d", &numbers3);
if (numbers3 < 0)
{
numbers2 = 1;
}
else
{
while (numbers3 <= 0 || numbers3 > numbers)
{
printf("\nInvalid entry, please enter a number between 1 and %dm
inclusive: ", numbers);
scanf("%d", &numbers3);
}
hightotal = 0;
lowtotal = 0;
for (averageday = 1; averageday <= numbers3;
averageday++)
{
hightotal += hightemp[averageday - 1];
lowtotal += lowtemp[averageday - 1];
}
averagetemp = (double) (hightotal + lowtotal) / (numbers3 * 2);
printf("\nThe average temperature up to day %d is: %.2lf",
numbers3, averagetemp);
}
}
printf("\nGoodbye!");
return 0;
}
/////////////////////////////////////////////////////////////////////////
why is it not working?
#define _CRT_SECURE_NO_WARNINGS
// Put your code below:
#include <stdio.h>
int main(void)
{
int day, hightemp[10], lowtemp[10], numbers, highesttemp,
highestday, lowesttemp, lowestday, numbers2 = 0, hightotal = 0,
lowtotal = 0, averageday = 0, numbers3;
double averagetemp;
printf("---=== IPC Temperature Calculator V2.0 ===---");
printf("\nPlease enter the number of days, between 3 and 10,
inclusive: ");
scanf("%d", &numbers);
// validate numbers is between [3,10], re-prompt until
valid
while (numbers < 3 || numbers > 10)
{
printf("\nInvalid entry, please enter a number between 3 and 10,
inclusive: ");
scanf("%d", &numbers);
printf("\n");
}
for (day = 1; day <= numbers; day++)
{
printf("Day %d - High: ", day);
scanf("%d", &hightemp[day - 1]);
printf("Day %d - Low: ", day);
scanf("%d", &lowtemp[day - 1]);
// if this is first day or highesttemp <= hightemp for day,
update highesttemp and highestday
if(day == 1 || highesttemp <= hightemp[day - 1]) // the array is
hightemp not highesttemp
{
highesttemp = hightemp[day - 1];
highestday = day; // this should be highestday
}
// if this is first day or lowesttemp >= lowtemp for day,
update lowesttemp and lowestday
if (day == 1 || lowesttemp >= lowtemp[day - 1]) // the array is
lowtemp not lowesttemp
{
lowesttemp = lowtemp[day - 1];
lowestday = day; // this should be lowestday
}
}
printf("\nDay Hi Low\n");
for (day = 1; day <= numbers; day++)
{
printf("%d %d %d\n", day, hightemp[day - 1], lowtemp[day -
1]);
}
printf("\nThe highest temperature was %d, on day %d\n", highesttemp, highestday);
printf("The lowest temperature was %d, on day %d\n", lowesttemp, lowestday);
while (numbers2 == 0)
{
printf("\nEnter a number between 1 and %d to see average
temperature for the entered number of days, enter a negative number
to exit: ", numbers);
scanf("%d", &numbers3);
if (numbers3 < 0)
{
numbers2 = 1;
}
else
{
while (numbers3 <= 0 || numbers3 > numbers)
{
printf("\nInvalid entry, please enter a number between 1 and %dm
inclusive: ", numbers);
scanf("%d", &numbers3);
}
hightotal = 0;
lowtotal = 0;
for (averageday = 1; averageday <= numbers3;
averageday++)
{
hightotal += hightemp[averageday - 1];
lowtotal += lowtemp[averageday - 1];
}
averagetemp = (double) (hightotal + lowtotal) / (numbers3 * 2);
printf("\nThe average temperature up to day %d is: %.2lf",
numbers3, averagetemp);
}
}
printf("\nGoodbye!");
return 0;
}
//end of program
Output: