1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
/*make a program that reads different temperatures from a file
from different distances off the ground and find the lowest temp, the highest
temp, and the average for each day. Then output them to a file */
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int day;
string local, name;
double sol, Day2MAvg, Day2HmAvg, Day2QmAvg, Day3MAvg, Day3HmAvg, Day3QmAvg;
double totalDay2M, totalDay2Hm, totalDay2Qm, totalday3M, totalDay3Hm, totalDay3Qm;
int NumDay = 0;
int Days = 0;
ofstream outdata ("output.dat");
ifstream indata ("pathfinder234X.dat");
if ( !indata )//if file doesnt open identify the user of the problem.
{
char cont;
cout << "There is a problem opening the file" <<endl;
}
else
cout <<"The file opened for reading" <<endl;
getline(indata, name);//skip the first four lines.
getline (indata, name);
getline (indata, name);
getline (indata, name);
while (!indata.eof()) //skip the first few variables then read the temperatures.
{
double DayM, DayHm, DayQm;
indata >> Days >> local >> sol >> DayM >>DayHm >>DayQm;
NumDay++; //increment the number of days
totalDay2M+=DayM; //add and make the total
totalDay2Hm+=DayHm;
totalDay2Qm+=DayQm;
Day2MAvg=totalDay2M/NumDay;//find average of the days
Day2HmAvg=totalDay2Hm/NumDay;
Day2QmAvg=totalDay2Qm/NumDay;
}
cout <<Day2MAvg <<endl; //out put the days onto the screen
cout <<Day2HmAvg <<endl;
cout <<Day2QmAvg; system ("pause");
return 0;
}
|