Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

hi, I have a problem in C language. I have written the code below. I need to code these -Display the highest temperature, and the

hi,

I have a problem in C language. I have written the code below. I need to code these

-Display the highest temperature, and the day on which it occurred

-Display the lowest temperature, and the day on which it occurred

-Calculate and display the mean (average) temperature for a period entered by the user, until the user enters -1.

The output must be like this:

The highest temperature was 9, on day 2

The lowest temperature was -9, on day 4

Enter a number between 1 and 5 to see the average temperature for the entered number of days, enter a negative number to exit: 6

Invalid entry, please enter a number between 1 and 5, inclusive: 3

The average temperature up to day 3 is: 2.67

Enter a number between 1 and 5 to see the average temperature for the entered number of days, enter a negative number to exit:5

The average temperature up to day 5 is: 1.20

Enter a number between 1 and 5 to see the average temperature for the entered number of days, enter a negative number to exit: -8

Goodbye!

Please correct me where I go wrong with some explanation.

Thank you,

#define _CRT_SECURE_NO_WARNINGS

// Start your code below:

#include

#define size 10

int main(void)

{

int nums;//number of days

int high_days[size]; // Array for temp high

int low_days[size]; // Array for temp low

int i, max, day_max, min, day_min;

int total_high = 0, total_low = 0;

double mean = 0;

printf("---=== IPC Temperature Calculator V2.0 ===--- ");

printf("Please enter the number of days, between 3 and 10, inclusive: ");

scanf("%d", &nums);

while (nums < 3 || nums > 10)

{

printf(" Invalid entry, please enter a number between 3 and 10, inclusive: ");

scanf("%d", &nums);

printf(" ");

}

for (i = 0; i < nums; i++)

{

printf("Day %d - High: ", i + 1);

scanf("%d", &high_days[i]);

printf("Day %d - Low: ", i + 1);

scanf("%d", &low_days[i]);

}

printf(" DayHiLow");

for (i = 0; i < nums; i++)

{

printf(" %d%d%d", i + 1, high_days[i], low_days[i]);

}

printf(" ");

max = high_days[0];

min = low_days[0];

for (i = 0; i < nums; i++)

{

if (max < high_days[i])

{

max = high_days[i];

day_max = i + 1;

printf(" The highest temperature was %d, on day %d", max, day_max);

}

if (min > low_days[i])

{

min = low_days[i];

day_min = i + 1;

printf(" The lowest temperature was %d, on day %d", min, day_min);

}

}

printf("Enter a number between 1 and 5 to see the average temperature for the entered number of days, enter a negative number to exit: ");

scanf("%d", &nums);

do

{

total_high = high_days[i];

total_low = low_days[i];

mean = (double)(total_high + total_low) / nums * 2;

printf(" The average temperature up to day %d is: %.2f", nums, mean);

} while (nums=0 || nums>5);

while (nums = 0 || nums > 5)

{

printf(" Invalid entry, please enter a number between 1 and 5, inclusive: ");

scanf("%d", &nums);

printf(" ");

}

while (nums < 0)

{

printf(" Goodbye!");

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions