HELPPPPPPP

so this code is supposed to take an input file with data and keep one line of the data is all 12 months are present. If not, then we simply keep the name and output "too few readings" i've been working on this for days, and can't seem to make my code work properly.
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  #include "Project2.h"
#include <string>
#include <iostream>

void weatherSummary ( string inputfile, string outputfile )
{
	ifstream in(inputfile); // read the data from the input file
	ofstream out(outputfile); // send my data to an output text file

	string name;
	double latitude;
	double longitude;
	double elevation;
	int TPCP;
	int MNTM;
	
	int counter;
	string lastStationName;
	string currentStationName;
	in.ignore(5000, '\n'); //ignore the header
	
	out << left << setw(18) << "STATION_NAME" << setw(18) << "ELEVATION" << setw(18) << " LATITUDE" << setw(18) << "LONGITUDE" << setw(18) << "TPCP" << setw(18) << "MNTM" << endl;
				
	//read data 
	 

	 while( !in.fail() )
	{		
			
			int counter=0;
			currentStationName = name;
			lastStationName = currentStationName;
			readData( in, name, elevation, latitude, longitude, TPCP, MNTM );
			counter++;
			while ( lastStationName == currentStationName && counter <= 12 ) // nested while loop 
			{
			
			//counter
			
			
			
			
			cout << counter << "   " << currentStationName << "   " << (currentStationName == lastStationName) << endl;
			
			currentStationName = name;
			readData( in, name, elevation, latitude, longitude, TPCP, MNTM );
			counter ++; // add one to the counter if statement is true
			
			}
		
		if ( counter < 12 )
		{
		
			out << name << ':' << "too few readings" << endl;
			counter =0;
		}
		
		else
		{
			out << left << name << setw(18) << elevation << setw(18) << latitude <<setw(18) << longitude << setw(18) << TPCP << setw(18) << MNTM << endl;
			counter = 0;
		}
		
	
	}
	
		//out
}
	

void readData(ifstream& in, string &name, double &elevation, double &latitude, double &longitude, int &TPCP, int &MNTM )
{
	string junk;
	getline( in, junk, ',' );//read from in, store in junk and stop
	//at the comma - and get rid of the comma in the process
	
	getline( in, name, ',' );
	in >> elevation;
	in.get();
	in >> latitude;
	in.get();	
	in >> longitude;
	in.get();
	in.ignore( 5000, ',' );//ignore the date line 
	in >> TPCP; //read the TPCP data 
	in.get();
	in.ignore(5000, ',');//ignore the missing line
	in.ignore(5000, ',');//ignore the consecutive line
	in >> MNTM;//get the data for temperature
	in.ignore (5000, '\n' );// ignore the rest of the line and end that line


}



int main ()
{
	weatherSummary( "US_partial.txt", "output.txt");
	
	
	return 0;
	
}



my header
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
#include <fstream>
#include <iostream>
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>

double latitude;
double longitude;
double elevation;
int TPCP;
int MNTM;

using std::string;
using std::ifstream;
using std::ofstream;
using std::cout;
using std::endl;
using std::getline;
using std::left;
using std::setw;
using std::cin;



void readData(ifstream& in, string &name, double& elevation, double& latitude, double& longitude,
	int &TPCP, int &MNTM );

void weatherSummary ( string inputfile , string outputfile );







input file


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
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
can't seem to make my code work properly.

Don't s'pose you'd be interested in expanding that and saying what the problem is?
Still, if you're not too busy, it might help.
Topic archived. No new replies allowed.