Hi I'm having a lot of problems with this homework problem due tomorrow.
The assignment is to make a program that can read data from a file and give out the wind chill, average temperature, average air speed, and average wind chill. It must also reject data that has a temperature (in fahrenheit) of larger than 50 or an air speed of larger the 120 mph. I haven't even written any function to calculate the average wind chill because I simply do not know how. There are definitely problems here, but I don't know how to correct or solve them.

An example of some of the data from the file is:
Temp Air speed
32 F 20
2 C 25

If a temperature is in Celsius the program must convert it back to fahrenheit.

Any help is appreciated.

#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>

using namespace std;

    ofstream outfile("WindChillOutfile.txt");
    ifstream infile("/Users/richiemizrahi/Documents/C++/WindChill/weather.dat");

double Ta, V, Twc;
double WindChill();
double AvgTemp();
double AvgAirSpeed();

int main()
{
    double T, Ta, V, Twc;
    char scale;

        if (!infile.is_open() ) {
        cout << endl << "ERROR: Unable to open file" << endl;
        exit(1);
        }

        while (!infile.eof() ) {
            infile >> T >> scale >> V;
            if(!scale == 'F') {
                Ta = (T * 9 / 5) + 32;
            }
            if( !Ta > 50 || V > 120){
               WindChill();
               AvgTemp();
               AvgAirSpeed();
            }else
                ;

    outfile << "The temperature is " << Ta << " F, " << endl;
    outfile << "the air speed is " << V << " mph, " << endl;
    outfile << "and the wind chill index is " << Twc << " F." << endl;
    outfile << endl;

    outfile << AvgTemp << endl;
    outfile << AvgAirSpeed << endl;

        }

    return 0;
}

double WindChill()
{

    Twc = 35.74 + (0.6215 * Ta) - (35.75 * pow(V,0.16)) + (.4275 * Ta * pow(V,0.16));

}

double AvgTemp()
{
    int counter;
    float average, number, sum;
    counter = 0;
    sum = 0;

    infile >> number;
    while ( !infile.eof() ){
        ++counter;
        sum = sum + number;
        infile >> number;
            ;
        infile >> number;
        }
    average = sum / counter;
    outfile << "The average temperature is " << average << " F, " << endl;
}

double AvgAirSpeed()
{
    int counter;
    float average, number, sum;
    counter = 0;
    sum = 0;

    infile >> number;
    while ( !infile.eof() ){
        ;
        infile >> number;
        ++counter;
        sum = sum + number;
        infile >> number;
        }
    average = sum / counter;
    outfile << "the average air speed is " << average << " mph, " << endl;
}

The assignment is to make a program that can read data from a file and give out the wind chill, average temperature, average air speed, and average wind chill. It must also reject data that has a temperature (in fahrenheit) of larger than 50 or an air speed of larger the 120 mph.

Good assignment.

I haven't even written any function to calculate the average wind chill because I simply do not know how.

That makes it very difficult to program anything.

There are definitely problems here, but I don't know how to correct or solve them.

Neither can we. You didn't bother telling us anything about them. All you did was say "here's my code -- fix it" which is not our thing. You need to say "one problem I have is (details of what's wrong and where). Another problem is (details of what and where)."

Well, one problem is that temperature comes out as zero and I don't know why, possibly something with the conversion function I made. The air speed comes out correct however.
Another problem is that the average temperature and airspeed always come out as true instead of giving me an actual number.
I also have a warnings in double windchill, double avgairspeed, and double avgtemp which say that "control reaches end of non-void function." I don't know what that means.

I also have a warnings in double windchill, double avgairspeed, and double avgtemp which say that "control reaches end of non-void function." I don't know what that means.

The functions are defined as double, therefore need to return a double at the end of the function.

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.