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)

}

What does the file look like, can you give a sample of a few lines of it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.