Last part of code, can't seem to get conversions correct

So, I've been working on this code for three days now for one of my classes and I am almost done. However, I need to calculate the total rainfall (the TPCP column) and the total temp ( the MTMN column) and find their average. My code doesn't seem to be eother converting the temperature the correct way from Celsius to F, and mm to in. I believe my logic makes sense within my code, but I'm new to c++ so I could very well be wrong, please help! Also, there is a divide by ten because we are a tenth of a decimal place off as stated in my homework instructions.
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
  #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, lastLatitude;
	double longitude, lastLongitude;
	double elevation, lastElevation;
	double newTotal;
	double TPCP, lastTPCP, newRain, convertedRain;
	double MNTM, lastMNTM, newTemp, convertedTemp;
	double totalRain;
	double totalTemp;
	double averageRain;
	double averageTemp;
	
	int count=0;
	string lastStationName;
	string currentStationName;
	in.ignore(5000, '\n'); //ignore the header
	lastStationName = "name";
	totalTemp =0;
	totalRain = 0;
	averageRain = 0;
	averageTemp = 0;
	
	
	out << left << setw(18) << "STATION_NAME" << setw(18) << "ELEVATION" << setw(18) << " LATITUDE" << setw(18) << "LONGITUDE" << setw(18) << "TPCP" << setw(18) << "MNTM" << endl;
	readData( in, currentStationName, elevation, latitude, longitude, TPCP, MNTM );	

		
	while( !in.fail() )
	{		
			
			
		if ( currentStationName == lastStationName )  
		{
			//comparing and not doing anything 
		
			
		}
		
		else if ( lastStationName != "name")
		{
			{
				totalRain = 0;
				totalTemp = 0;
				
			}
			if ( count == 12 )
			{
				
				convertData ( MNTM, TPCP );
				totalRain += TPCP;
				totalTemp =+ MNTM;
				double averageRain = totalRain / 12;
				double averageTemp = totalTemp / 12;
				out << left << lastStationName << setw(18) << lastElevation << setw(18) << lastLatitude <<setw(18) << lastLongitude << setw(18) << averageRain << setw(18) << averageTemp << endl;
				count = 0; //resetting counter
				totalRain = 0; // reset total for next set of data input 
				totalTemp = 0; // reset total for next set of data input
			}
			
			else
			{
				out << currentStationName << ':' << "too few readings" << endl;
				count = 0;
			}
		} 
		count ++; // add one to the counter if statement is true
		cout << count << " " << currentStationName << " " << lastStationName<< endl;
		lastStationName = currentStationName;
		lastElevation = elevation;
		lastLatitude = latitude;
		lastLongitude = longitude;
		lastMNTM = MNTM;
		lastTPCP = TPCP ;
		readData( in, currentStationName, elevation, latitude, longitude, TPCP, MNTM );	
		
	}
	
			if ( count == 12 )
			{
			
				out << left << lastStationName << setw(18) << lastElevation << setw(18) << lastLatitude <<setw(18) << lastLongitude << setw(18) << lastTPCP << setw(18) << lastMNTM << endl;
				count = 0;
			}
			
			else
			{
				out << currentStationName << ':' << "too few readings" << endl;
				count = 0;
			}
		
}



void convertData( double &convertedTemp, double &convertedRain)
{
	
	if ( TPCP == -9999 )
		convertedRain = 0;
	
	else 
		convertedRain = ( TPCP / 10 ) * 0.039370 ;
	
	if ( MNTM == -9999 )
		convertedTemp = 0;
	
	else 
		convertedTemp = ( MNTM / 10 ) * (9/5) + 32.00 ;
	
	
	
}

void readData(ifstream& in, string &name, double &elevation, double &latitude, double &longitude, double &TPCP, double &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;
	
}



here is 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
30
31
32
33
34
35
36
37
 #include <fstream>
#include <iostream>
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>



double TPCP;
double MNTM;
double totalRain;
double totalTemp;





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,
	double &TPCP, double &MNTM );

void weatherSummary ( string inputfile , string outputfile );

void convertData(double &convertedTemp, double &convertedRain);


and here is a sample input data file to test the codes

1
2
3
4
5
6
7
8
9
10
11
12
13
STATION,STATION_NAME,ELEVATION,LATITUDE,LONGITUDE,DATE,TPCP,Missing,Consecutive Missing,MNTM,Missing,Consecutive Missing
GHCND:USC00448941,WAYNESBORO WATER TREATMENT VA US,387.1,38.0802,-78.875,20150101,506,0,0,-1,0,0
GHCND:USC00448941,WAYNESBORO WATER TREATMENT VA US,387.1,38.0802,-78.875,20150201,392,0,0,-31,0,0
GHCND:USC00448941,WAYNESBORO WATER TREATMENT VA US,387.1,38.0802,-78.875,20150301,851,0,0,52,0,0
GHCND:USC00448941,WAYNESBORO WATER TREATMENT VA US,387.1,38.0802,-78.875,20150401,1265,0,0,118,0,0
GHCND:USC00448941,WAYNESBORO WATER TREATMENT VA US,387.1,38.0802,-78.875,20150501,295,0,0,186,0,0
GHCND:USC00448941,WAYNESBORO WATER TREATMENT VA US,387.1,38.0802,-78.875,20150601,1497,0,0,225,0,0
GHCND:USC00448941,WAYNESBORO WATER TREATMENT VA US,387.1,38.0802,-78.875,20150701,748,0,0,234,0,0
GHCND:USC00448941,WAYNESBORO WATER TREATMENT VA US,387.1,38.0802,-78.875,20150801,264,0,0,221,0,0
GHCND:USC00448941,WAYNESBORO WATER TREATMENT VA US,387.1,38.0802,-78.875,20150901,2542,0,0,195,0,0
GHCND:USC00448941,WAYNESBORO WATER TREATMENT VA US,387.1,38.0802,-78.875,20151001,1792,0,0,122,0,0
GHCND:USC00448941,WAYNESBORO WATER TREATMENT VA US,387.1,38.0802,-78.875,20151101,685,0,0,89,0,0
GHCND:USC00448941,WAYNESBORO WATER TREATMENT VA US,387.1,38.0802,-78.875,20151201,950,0,0,83,0,0

9/5, in C++, is 1. An int divided by an int returns an int.

A double divided by an int will return a double. Try 9.0/5

TPCP == -9999 Here, you are trying to compare a floating point number to an exact value. This is very dangerous. Read about it here: http://floating-point-gui.de/

Now, get better at debugging and get better at telling us what's going wrong. At the start of the function convertData, what are the values of everything that matters? At the end of that function, what are the values of everything that matters? In what way are those values not what you intended them to be?
Topic archived. No new replies allowed.