0

So i have to create a program which reads the number of days in the month and the temperatures. This info is in other file, temp.dat. I have how to calculate the average temperatures, but am having trouble reading from the file. Also, for every day that is in a string of 3 or more consecutive days above the average, i have to display a “+” beside the temperature. Can anyone give me a hint.. i'm stuck!

#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{

    int n;

    ifstream file;
        file.open("temp.doc");
        if(file.fail)
        {
            cout<<"Unable to open this file"<<endl;

        }

    else
    {
        file>>n;
        cout<<"Value of n is "<<endl;
    }



    vector<double> temps;
    double temp;

    while (cin>>temp)
    {
       temps.push_back(temp);
    }

    double sum = 0;
    for (int i=0; i < temps.size(); ++i)
    {
       sum += temps[i];
    }

    float avg = sum/temps.size();
    cout << "The average temperature for the month is: " << avg << endl;


    //if (high)

}

Edited by Reverend Jim: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by jonsca
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.