SOS not getting proper output

I have an assignment that takes an input of weather data and processes to give an output in the form of a table

It takes the input:

STATION,STATION_NAME,ELEVATION,LATITUDE,LONGITUDE,DATE,TPCP,Missing,Consecutive Missing,MNTM,Missing,Consecutive Missing
GHCND:US1VACP0007,CULPEPER 6.1 W VA US,177.7,38.4595,-78.1136,20150101,23,0,0,-9999,0,0
GHCND:US1VACP0007,CULPEPER 6.1 W VA US,177.7,38.4595,-78.1136,20150201,722,0,0,-9999,0,0
GHCND:US1VACP0007,CULPEPER 6.1 W VA US,177.7,38.4595,-78.1136,20150301,211,0,0,-9999,0,0
GHCND:US1VACP0007,CULPEPER 6.1 W VA US,177.7,38.4595,-78.1136,20150401,1198,0,0,-9999,0,0
GHCND:US1VACP0007,CULPEPER 6.1 W VA US,177.7,38.4595,-78.1136,20150501,671,0,0,-9999,0,0
GHCND:US1VACP0007,CULPEPER 6.1 W VA US,177.7,38.4595,-78.1136,20150601,647,0,0,-9999,0,0
GHCND:US1VACP0007,CULPEPER 6.1 W VA US,177.7,38.4595,-78.1136,20150701,768,0,0,-9999,0,0
GHCND:US1VACP0007,CULPEPER 6.1 W VA US,177.7,38.4595,-78.1136,20150801,112,0,0,-9999,0,0
GHCND:US1VACP0007,CULPEPER 6.1 W VA US,177.7,38.4595,-78.1136,20150901,1592,0,0,-9999,0,0
GHCND:US1VACP0007,CULPEPER 6.1 W VA US,177.7,38.4595,-78.1136,20151001,20,0,0,-9999,0,0
GHCND:US1VACP0007,CULPEPER 6.1 W VA US,177.7,38.4595,-78.1136,20151101,296,0,0,-9999,0,0
GHCND:US1VACP0007,CULPEPER 6.1 W VA US,177.7,38.4595,-78.1136,20151201,193,0,0,-9999,0,0
GHCND:USC00442009,CORBIN VA US,67.1,38.2022,-77.3747,20150101,799,0,0,12,0,0
GHCND:USC00442009,CORBIN VA US,67.1,38.2022,-77.3747,20150201,563,0,0,-12,0,0
GHCND:USC00442009,CORBIN VA US,67.1,38.2022,-77.3747,20150301,998,0,0,67,0,0
GHCND:USC00442009,CORBIN VA US,67.1,38.2022,-77.3747,20150401,1183,0,0,142,0,0
GHCND:USC00442009,CORBIN VA US,67.1,38.2022,-77.3747,20150501,614,0,0,208,0,0
GHCND:USC00442009,CORBIN VA US,67.1,38.2022,-77.3747,20150601,1585,0,0,237,0,0
GHCND:USC00442009,CORBIN VA US,67.1,38.2022,-77.3747,20150701,965,0,0,248,0,0
GHCND:USC00442009,CORBIN VA US,67.1,38.2022,-77.3747,20150801,249,0,0,238,0,0
GHCND:USC00442009,CORBIN VA US,67.1,38.2022,-77.3747,20150901,1459,0,0,219,0,0
GHCND:USC00442009,CORBIN VA US,67.1,38.2022,-77.3747,20151001,1225,0,0,140,0,0
GHCND:USC00442009,CORBIN VA US,67.1,38.2022,-77.3747,20151101,614,0,0,113,0,0
GHCND:USC00442009,CORBIN VA US,67.1,38.2022,-77.3747,20151201,97,0,0,89,13,7
GHCND:USC00440187,AMELIA 4 SW VA US,105.2,37.3451,-77.9781,20150101,814,0,0,23,4,1
GHCND:USC00440187,AMELIA 4 SW VA US,105.2,37.3451,-77.9781,20150201,941,0,0,-7,3,1
GHCND:USC00440187,AMELIA 4 SW VA US,105.2,37.3451,-77.9781,20150301,1065,0,0,75,5,1
GHCND:USC00440187,AMELIA 4 SW VA US,105.2,37.3451,-77.9781,20150401,1086,0,0,148,1,1
GHCND:USC00440187,AMELIA 4 SW VA US,105.2,37.3451,-77.9781,20150501,329,0,0,206,0,0
GHCND:USC00440187,AMELIA 4 SW VA US,105.2,37.3451,-77.9781,20150601,1880,0,0,244,1,1
GHCND:USC00440187,AMELIA 4 SW VA US,105.2,37.3451,-77.9781,20150701,929,0,0,249,4,2
GHCND:USC00440187,AMELIA 4 SW VA US,105.2,37.3451,-77.9781,20150801,694,0,0,242,3,1

then I am required to make the output:

STATION_NAME ELEVATION LATITUDE LONGITUDE TPCP MNTM
CULPEPER 6.1 W VA US 177.7 38.4595 -78.1136 2.11713 0
CORBIN VA US 67.1 38.2022 -77.3747 3.396 57.515
AMELIA 4 SW VA US: too few readings

Here's my Code:

#include <fstream>
#include <string>
#include <iostream>

using std::endl;
using std::ifstream;
using std::ofstream;
using std::string;
using std::getline;
using std::cout;

void weatherSummary( string , string );

void readData ( ifstream& in, string& name, string& ele, string& lat, string& log, double& tpcp, double& temp );

double fahrCon ( double& temp );

double inCon ( double& tpcp );

void weatherSummary( string inputfile, string outputfile)
{
ifstream in(inputfile); //open files to be used
ofstream out(outputfile);

string name; //Name of station
string namechg; //string to check if still at the same station
string ele; //Elevation
string oldele;
string lat; //Lattitude
string oldlat;
string log; //Longitude
string oldlog;
double tpcp; //total rainfall in mm to be converted to inches
double oldtpcp;
double temp; //1/10 degree celsius to be converted to fahrenheit
double oldtemp;
double tempavg; //Variable for average temperature
double tpcpavg; //Variable for average rainfall
double tempsum; //Stores the sum of the temp to be used for the average
double tpcpsum; //Stores the sum of the rainfall to be used for the average
int totdata; //Counter for total data points

//Make top of table
out << "STATION_NAME\t" << "ELEVATION\t" << "LATITUDE\t" << "LONGITUDE\t" << "TPCP\t" << "MNTM\n";

in.ignore(5000, '\n'); //Ignore the first line of data

tempsum = 0; //initialize sums as 0
tpcpsum = 0;
totdata = 0;

readData(in, name, ele, lat, log, tpcp, temp ); //inport first line

totdata++; //count the number of data points from the current station

namechg = name; //initiate the first station name as the old name

while ( !in.fail() )
{

if ( name == namechg )
{
if ( temp == -9999 )
{
temp = 0;
}
tempsum += temp;
tpcpsum += tpcp;
namechg = name;
oldele = ele;
oldlat = lat;
oldlog = log;
totdata++;
}
if ( totdata >= 12 )
{
tempavg = tempsum/12;
tempavg = fahrCon( tempavg );
tpcpavg = tpcpsum/12;
tpcpavg = inCon( tpcpavg );
out << namechg << "\t" << oldele << "\t" << oldlat << "\t" << oldlog << "\t"
<< tpcpavg << "\t" << tempavg << endl;
tempsum = 0; //reset sums as 0
tpcpsum = 0;
totdata = 0;
}
if ( totdata < 12 && name != namechg )
{
out << name << ":\ttoo few readings" << endl;
tempsum = 0; //reset sums as 0
tpcpsum = 0;
totdata = 0;
}

namechg = name;
totdata++;
readData(in, name, ele, lat, log, tpcp, temp );

}

}

void main()
{
weatherSummary( "input.txt", "output.txt");
}

//function to inport the next line of data
void readData ( ifstream& in, string& name, string& ele, string& lat, string& log, double& tpcp, double& temp )
{
in.ignore(5000, ','); //ignore the station id
getline( in, name, ','); //get station name as a string
getline( in, ele, ','); //get elevation as a string
getline( in, lat, ','); //get latitude as a string
getline( in, log, ','); //get longitude as a string
in.ignore(5000, ','); //ignore the date
in >> tpcp; //get the precipitation as a double
in.ignore(5000, ','); //ignore missing
in.ignore(5000, ','); //ignore consecutive missing
in >> temp; //get MNMT as a double
in.ignore(5000, '\n'); //ignore the rest of the line
}

//function to convert the temperature to degrees fahrenheight
double fahrCon ( double& temp )
{
temp = temp / 10; //convert tenths of degrees celsius to full degrees
temp = temp * 9/5 + 32; //convert celsius to fahrenheit
return temp;
}

//function to convert millimeters to inches
double inCon ( double& tpcp )
{
tpcp = tpcp * 5/127; //convert millimeters to inches
return tpcp;
}

And it's giving the output it's giving:

STATION_NAME ELEVATION LATITUDE LONGITUDE TPCP MNTM
CULPEPER 6.1 W VA US 177.7 38.4595 -78.1136 11.3911 32
CULPEPER 6.1 W VA US 177.7 38.4595 -78.1136 9.78018 32
CORBIN VA US: too few readings
CORBIN VA US 67.1 38.2022 -77.3747 19.3832 32
AMELIA 4 SW VA US: too few readings
AMELIA 4 SW VA US 105.2 37.3451 -77.9781 20.4396 32

I'm not sure what I am doing wrong and I have been staring at this for hours. Any help would be appreciated
Last edited on
Topic archived. No new replies allowed.