Kat H.

asked • 06/28/21

Write a C++ program that takes in a set of daily average temperatures (up to a maximum of 30).

Write a program that takes in a set of daily average temperatures (up to a maximum of 30). Please include source code.


Do the following algorithm:

  1. Ask the user for a temperature
  2. If the user enters a -1 then stop asking for temperatures.
  3. After the user is done entering temperatures:

a. Print out the temperatures entered.

b. print out the average, high and low temperatures.

To get average, use:

average = (sum of temps) divided by (count of temps)

to get max or min, either keep track of the max or min as the user enters a number or you can do this later when printing the temperatures. Do this by comparing the current max

value to the number and replacing it if it is bigger (smaller for min).


for example:

if(array[i] > max)

max = array[i];

you can initialize max to 0 and min to some large number (1000) for this exercise but in the future (during exams) you should set it to the first element in the list.


NOTE: Use floating point type for all numbers to prevent truncating the decimal part of the average.


Requirements:


You must enter temperatures into an array and use this array for calculating the average and print out the temperatures.


Use two loops, one for entering numbers and one for printing the temperatures.


--------------------------------

EXAMPLE OUTPUT #1

--------------------------------


Enter temperature (enter -1 to quit):

89

Enter temperature (enter -1 to quit):

78

Enter temperature (enter -1 to quit):

65

Enter temperature (enter -1 to quit):

77

Enter temperature (enter -1 to quit):

90

Enter temperature (enter -1 to quit):

79

Enter temperature (enter -1 to quit):

-1

The temperatures are: 89 78 65 77 90 79

The average temperature is: 79.6667

The maximum temperature is: 90

The minimum temperature is: 65


--------------------------------

EXAMPLE OUTPUT #2

--------------------------------

Enter temperature (enter -1 to quit):

20

Enter temperature (enter -1 to quit):

18

Enter temperature (enter -1 to quit):

45

Enter temperature (enter -1 to quit):

34

Enter temperature (enter -1 to quit):

56

Enter temperature (enter -1 to quit):

45

Enter temperature (enter -1 to quit):

37

Enter temperature (enter -1 to quit):

37

Enter temperature (enter -1 to quit):

-1

The temperatures are: 20 18 45 34 56 45 37 37

The average temperature is: 36.5

The maximum temperature is: 56

The minimum temperature is: 18


1 Expert Answer

By:

Patrick B. answered • 06/29/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.