QuestionQuestion

A file gives all of the temperatures for a period of time. Each number in the file is the temperature for 1 day. The number of days could be a month, a year, or the duration of a trip. You are to read in all of the temperatures from the file and print the following statistics:

The number of days
The temperature range, example: The temperatures ranged from -5 to 45
The average temperature
The number of days (if any) that were freezing (32 degrees or less). Don't print if 0!
The number of days (if any) that were 100 degrees or more. Don't print if 0!
Example 1:
The file contains these numbers:
20
15
32
40
37
Output:
There were 5 days.
The temperatures ranged from 15 to 40.
The average temperature was 28.8
It was freezing on 3 days.
Example 2:
The file contains these numbers:
85
90
95
100
102
70
80
90
Output:
There were 8 days.
The temperatures ranged from 70 to 102.
The average temperature was 89.
It was 100 degrees or more on 2 days.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream inFile;
    char data[5];
    int count = 0, min, max, total = 0, freezing = 0, hot = 0;
    double average;
    inFile.open("input.txt", ifstream::in);

    while(!inFile.eof())
    {
   inFile.getline(data, 5);
   int num = atoi(data);
   if(count == 0 || max < num)
max = num;
   if(count == 0 || min > num)
min = num;
   if(num <= 32)...
$20.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats