//This is a funciton that computes the average temp per day and for the month
//Written by Ben Hogan and Diana Moore
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
void temperature (ofstream outfile)
{
//declares these identifiers
float temp, avg, sum, time, avgmon, tottemp;
int loop_count, day, jday, errtotal, findays;
ifstream temp_file; //declaring temp_file
temp_file.open("89381099.txt"); //opens racerrock1099 to read in info
//initilize variables
tottemp = 0;
day = 0;
temp_file.ignore(100,'\n'); //ignores first 2 lines file
temp_file.ignore(100,'\n');
outfile<<"Day"<<" "<<"Average Temp in °C"<<" "<<"errors (out of 144)"<>jday; //reads in jday
while (temp_file) //loops till end of file
{
//initilize variables
loop_count = 1;
errtotal = 0;
sum = 0;
while (loop_count <= 144) //loops 144 times
{
temp_file>>time>>temp; //reads in time and temp
temp_file.ignore(50,'\n'); //ignores rest of line
if (temp != 444.0) //if then statement to find sum and number of errors
sum = sum + temp;
else
errtotal = errtotal + 1;
loop_count++; //adds one to loopcount
temp_file >>jday; //reads in jday
} //end of loop
findays = 144 - errtotal; //computes number of days that the temp was recorded
avg = sum / findays; //computes average
tottemp = tottemp + avg; //computes the total temperature
day = day + 1; //value for day
avgmon = tottemp / day; //finds the average temp for the month
outfile<< setiosflags (ios::showpoint | ios::fixed); //sets precision to 2
outfile<< setprecision (2);
outfile<< setw(2) << day << setw(15) << avg << setw(19) << errtotal << endl; //displays values
} //end of loop
outfile << "\n\n";
outfile << "The average temp. for the month is " << avgmon << " °C."<< endl; //displays average temp for month
}