Switch from parallel arrays to array of structs, identifier promlem.

I'm trying to switch a code that was set up with parallel arrays to use an array of structs instead but I can not figure out how to identify everything now.
Here is my code if someone could help me out.


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
struct players
{
string fname,lname;
int game;
float ftm,fta,tpm,tpa,fgm,fga;
double ftp,tpp,fgp,pts,ppg;
};

bool validate_points(float ftm[], float tpm[], float fgm[], double pts[], int j);    //boolean functions to validate the data
bool validate_ftp(float ftm[], float fta[], double ftp[], int j);
bool validate_tpp(float ttm[], float tpa[], double tpp[], int j);
bool validate_fgp(float fgm[], float fga[], double fgp[], int j);
bool validate_ppg(int game[], float ftm[], float tpm[], float fgm[], double pts[], double ppg[], int j);

bool validate_ftp(float ftm[], float fta[], double ftp[], int j)
{
	double cv;
	cv=(double)ftm[j]/fta[j];
	cv=cv*100;
	if ((cv>=ftp[j]-.05)&&(cv<ftp[j]+.05))
		return true;
	else 
		return false;
}
bool validate_points(float ftm[], float tpm[], float fgm[], double pts[], int j)
{
	double cv;
	cv=(double)ftm[j]+tpm[j]+2*fgm[j];
	if((cv>=pts[j]-.05)&&(cv<pts[j]+.05))
		return true;
	else return false;
}
bool validate_tpp(float ttm[], float tpa[], double tpp[], int j)
{
	double cv;
	cv=(double)ttm[j]/tpa[j];
	cv=cv*100;
	if ((cv>=tpp[j]-.05)&&(cv<tpp[j]+.05))
		return true;
	else 
		return false;
}
bool validate_fgp(float fgm[], float fga[], double fgp[], int j)
{
	double cv;
	cv=(double)fgm[j]/fga[j];
	cv=cv*100;
	if ((cv>=fgp[j]-.05)&&(cv<fgp[j]+.05))
		return true;
	else 
		return false;
}
bool validate_ppg(int game[], float ftm[], float tpm[], float fgm[], double pts[], double ppg[], int j)
{
	double cv;
	cv=(double)(ftm[j]+tpm[j]+2*fgm[j])/game[j];
	if((cv>=ppg[j]-.05)&&(cv<ppg[j]+.05))
		return true;
	else return false;
}


int main()
{
	ifstream indata;
	indata.open("NCAA_Stats.txt");   //open NCAA Stats
	ofstream outdata;
	outdata.open("error_log.txt");   //Creating the error log
	outdata.open("validData.txt");
	players stats[55];  

	string sfname,slname, sgame, sftm, sfta, sftp, stpm, stpp, sfgm, sfga, sfgp, spts, sppg;
	indata>>sfname>>slname>>sgame>>sgame>>sftm>>sfta>>sftp>>stpm>>stpp>>sfgm>>sfga>>sfgp>>spts>>sppg;
	
	int i=0;

	while(!indata.eof())  //while loop that runs until the end of file
	{
		indata>>stats[i].fname>>stats[i].lname>>stats[i].game>>stats[i].ftm>>stats[i].fta>>stats[i].ftp>>stats[i].tpm>>stats[i].tpa>>stats[i].tpp>>stats[i].fgm>>stats[i].fga>>stats[i].fgp>>stats[i].pts>>stats[i].ppg;
		i++;
	}
	int count=0;

		outdata<<"Statistical Error long:"<<"\n";  // Header for error log
		outdata<<" "<<"\n";

	for (int j=0; j<i ;j++)  //for loop to find errors
	{
		if(!validate_ftp(ftm,fta,ftp,j))
		{
			count++;
			outdata<<"\t"<<"free throw percentage error:"<<"\t"<<fname[j]<<"\t"<<lname[j]<<"'s ft% is wrong:  "<<ftp[j]<<"\n";
		}
		if(!validate_points(ftm,tpm,fgm,pts,j))
		{	
		count++;
		outdata<<"\t"<<"total points error:"<<"\t"<<fname[j]<<"\t"<<lname[j]<<"'s total points is wrong:  "<<pts[j]<<endl;
		}
		if(!validate_tpp(tpm,tpa,tpp,j))
		{
		    count++;
		    outdata<<"\t"<< "3 point percentage error:"<<"\t"<<fname[j]<<"\t"<<lname[j]<<"'s tp% is wrong:  " <<tpp[j]<<endl;
		}
	    if(!validate_fgp(fgm,fga,fgp,j))
		{	
		    count++;
		    outdata<<"\t"<< "field goal error:" <<"\t"<<fname[j]<<"\t"<<lname[j]<<"'s fgp is wrong:  "<<fgp[j]<<endl;
		}
		if(!validate_ppg(game,ftm,tpm,fgm,pts,ppg,j))
		{
		count++;  
		}
		
	}
	outdata<<"\t"<< "the total number of errors are:  "<<count<< endl;  // total number of errors
	
	indata.close();     //close NCAA_Stats.text
	outdata.close();    //close error_log
	return 0;
}
Last edited on
Topic archived. No new replies allowed.