//This function computes the average wind chill per day //Written by Adam Plumb and Max Indelicato #include <iostream.h> #include <fstream.h> #include <math.h> #include <iomanip.h> void wind_chill (ofstream outfile) { double C, H, Spd, T, sum, ten_min, average, JD, pressure; //declares variables as data type double int real_info, bad, loop_count, day; //declares variables as data type int ifstream inputfile; //declares inputfile inputfile.open("89381099.txt"); //opens input text file (varies) inputfile.ignore(500, '\n'); //ignores first line of inputfile inputfile.ignore(500, '\n'); //ignores second line of inputfile day = 1; //initializes day as equaling 1 outfile << "\n\n\n"; outfile << "DAY" << " " << "AVERAGE WINDCHILL" << " " << "# OF ERRORS" << endl;//outputs labels of ouputfile outfile << "------------------------------------------------------------------------------" << endl; while( inputfile ) //end-of-file while loop initialized { loop_count = 1; //initializes loop_count as equaling 1 bad = 0; //initializes bad as equaling 0 real_info = 0; //initializes real_info as equaling 0 sum = 0; //initializes sum as equaling 0 inputfile >> JD; //gets initial Julian Day while(loop_count <= 144) //initiates loop { inputfile >> ten_min >> T >> pressure >> Spd; //reading in file inputfile.ignore(500, '\n'); //ignores the rest of the line if(pressure != 444.0 && T != 444.0 && Spd != 444.0) //If statement { H = ( 10.9 * sqrt( Spd ) + 9 - Spd ) * ( 33 - T ); //computing H C = 33 - ( H / 22.41492783 ); //computing windchill sum = sum + C; //adding a total real_info++; //counting number of times } else //else statement bad++; loop_count++; //adding 1 to loop_count inputfile >> JD; //reading in JD } //end of inside while loop average = sum / real_info; //gets average outfile << setiosflags(ios::showpoint | ios::fixed); //declaring iosflags outfile << setprecision(2); //sets precision to 2 //outputs words to file outfile << setw(2) << day << setw(21) << average << " ºC" << setw(25) << bad << endl; //adds one to day day++; } //end of outside while loop }