Site hosted by Angelfire.com: Build your free website today!
//This is a function that computes the average pressure per day

// Created by Emily Weckback and Julian Salai  1/28/00


#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>

void pressure(ofstream outfile)
{
	//defines all identifiers
	ifstream input;

	float jday, tmp, temp;
	int loop_count, day;
	float pressure, press_sum, pressure_average;
	int  error_count, non_error; 

	//opens input and output files
	input.open("89381099.txt");


	//ignores the first 2 lines of code
	input.ignore(600, '\n');
	input.ignore(600, '\n');

	//print header
	outfile << "\n\n\n";
	outfile << "  Day  " << "  Avg Pressure  " << "  Num of Errors" << endl;
	day = 0;
	input>> jday;
	while (input)
	{
		//reassigns all identifiers values
		loop_count = 1;
		press_sum = 0;
		error_count = 0;
		non_error = 0;
		
		//loops as long as loop_count is less than or equal to 144
		while(loop_count <= 144)
		{
			input>> tmp>>temp>>pressure;
			input.ignore(50,'\n');
			if(pressure != 444.0)//if, else statement
			{
				press_sum = press_sum + pressure;
				non_error++;
			}
			else
				error_count ++;
			
			loop_count ++;//adds one to loop_count
			input>> jday;
		}
		day++;
		pressure_average = press_sum  / non_error;
		
		//prints the information to the screen
		outfile << setiosflags(ios::showpoint | ios::fixed);
		outfile << setprecision (2);
		outfile << setw(2) << day<< setw(15) << pressure_average << setw(14) << error_count << endl;
	}

}