hi guys,

need help urgently on extracting data from text file and compute it.

i'm suppose to sum up the highest temp and divide them by 7 to get an average decimal.

only display data on compiler without calculating the average sum.

ok here is my code.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;
class Weather
{
public:
    Weather() {};
    void getweek3htemp(Weather myWeather[]);
    void viewhtemp(double);
    static int numWeather;
    void setInfo(int,double,double,double,double,string);

private:
    int day;
    double htemp;
    double ihtemp;
    double wkavg;
    double ltemp;
    double humdity;    
    double rain;
    string condition;

};

int Weather::numWeather = 0;

void readFile(Weather[]);

void Weather::setInfo(int inday, double inltemp,double inhtemp,double inhumdity,double inrain,string incondition )
{
    day = inday;
    ltemp = inltemp;
    htemp=inhtemp;
    humdity=inhumdity;
    rain=inrain;
    condition=incondition;
}

void Weather::viewhtemp(double)
{     

     cout << "Highest Temperature: " << htemp << endl;
     cout<< wkavg<<endl; 
     wkavg=wkavg+htemp;

}

void Weather::getweek3htemp(Weather myWeather[])
{

     for(day=14;day<21;day++)        
     myWeather[day].viewhtemp(htemp);                               
     wkavg=wkavg/7;
     cout << "average of the week"<< wkavg<< endl;
}


void readweek3(Weather[]);


int main(void)
{
    Weather myWeather[500];

    cout << "Reading Statistics from file" << endl;
    readFile(myWeather);

    cout << "Display week 3 information" << endl;    
    readweek3(myWeather);
    system("pause");

    return 0;
}

void readweek3(Weather myWeather[])
{

     ifstream fin;
   char filename[50];
    cout << "Enter filename (including .txt):" << endl;
    cin>>filename;
    fin.open(filename);
   if (!fin.good())
    {
     cout << "File not found" << endl;
        exit(1);
    }

    while(!fin.eof())
    {
        int num =-1;      
        myWeather[num].getweek3htemp(myWeather);
        break;                
    }
    fin.close();
    system("pause");

}

void readFile(Weather myWeather[])
{
  int day,num;
  double ltemp,htemp,humdity,rain;
  string condition;

    ifstream fin;
   char filename[50];
    cout << "Enter filename (including .txt):" << endl;
    cin>>filename;
    fin.open(filename);
   if (!fin.good())
    {
     cout << "File not found" << endl;
        exit(1);
    }

    while(!fin.eof())
    {
        fin >> day >> ltemp >> htemp >> humdity >> rain >> condition;
        num = Weather::numWeather;
        myWeather[num].setInfo(day,ltemp,htemp,humdity,rain,condition);
        Weather::numWeather++;
    }
    fin.close();
    system("pause");

}

Try again. This time post your code between code tags (

[noparse][code=cpp] // code goes here 
[/code][/noparse]

).
And you might want to ask a question this time ;)

i've tried already but still can't. any kind soul to advise on my codes?

i've tried already but still can't. any kind soul to advise on my codes?

> If you post just use the button with the sharp: '#' and it will generate code tags for you, now you just have to paste your code between them, is that difficult? NO!

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.