Cannot convert double to double?

It seems like all of my doubles are written exactly the same, but only my first double (3rd argument) is coming up with an error when I call my calcStats function. What am I missing?
Thanks for the help!

/*********************************************************
CSCI 240 Program 8 Fall 2011

Programmer:

Section:
TA:

Date Due: 11/11/2011

Purpose: This is the second part of the assignment, that requires the building
of arrays to put together the structures of the team information.
**********************************************************/


#include <iostream>
#include <iomanip>
#include <fstream>

#define MAXTEAMS 48

using namespace std;

struct teamInfo
{
char schoolName[20];
char teamName[20];
int game1Score;
int game2Score;
int game3Score;
};

void calcStats(teamInfo[], int, double, double, double, int, int);
void printArray(teamInfo[], int);
int buildArray(teamInfo[]);

int main()
{
teamInfo teamAr[MAXTEAMS];
int teamcount, game1, game2, game3, totscore, loclow, lochigh;
double avgGame1, avgGame2, avgGame3;

teamcount = buildArray(teamAr);

printArray( teamAr, teamcount);

calcStats( teamAr, teamcount, &avgGame1, &avgGame2, &avgGame3, &lochigh, &loclow);

cout << "Tiddly-Winks Tournament Statistics\n";
cout << "----------------------------------";
cout << "Average Game 1 Score\t" << avgGame1 << endl;
cout << "Average Game 2 Score\t" << avgGame2 << endl;
cout << "Average Game 3 Score\t\n" << avgGame3 << endl;
cout << "Highest Scoring Team\t" << teamAr[lochigh].teamName << endl;
cout << "Lowest Scoring Team\t" << teamAr[loclow].teamName << endl;

system("pause");
return 0;
}

/********************************************************************
This function is used to calculate various stats from the tournament. It
the array, the count of teams, the averages of the games, and the location
of the highest and lowest scores as its arguments
*********************************************************************/

void calcstats (teamInfo teamAr[], int teamcount, double &avgGame1, double &avgGame2,
double &avgGame3, int &lochigh, int &loclow)
{
int i;
double sum1 = 0.00, sum2 = 0.00, sum3 = 0.00;

int temphigh,templow, total;

for (i == 0; i < teamcount; i++)
{
sum1 = sum1 + teamAr[i].game1Score;
sum2 = sum2 + teamAr[i].game2Score;
sum3 = sum3 + teamAr[i].game3Score;

total = teamAr[i].game1Score + teamAr[i].game2Score + teamAr[i].game3Score;

if ( total > temphigh)
{
temphigh = total;
lochigh = i;
}

if ( total < templow)
{
templow = total;
loclow = i;
}

}

avgGame1 = sum1 / teamcount;
avgGame2 = sum2 / teamcount;
avgGame3 = sum3 / teamcount;

}

/********************************************************************
This function totals up the score of all three games, and also displays all
of the information gathered in the tournament by printing the array. It has
the teaminfo array and number of teams as its arguments.
********************************************************************/

void printArray (teamInfo teamAr[], int teamcount)
{
int i, total, sub = 0;
cout << "\t\tBig 9 Conference Tiddly-Winks Tournament\n\n";
cout << "School Name\t" << "Team Name\t" << "Game 1 " << "Game 2 ";
cout << "Game 3 " << "Total Score\n";
cout << "--------------------------------------------------------\n\n";
for (i == 0; i < teamcount; i++)
{
total = teamAr[i].game1Score + teamAr[i].game2Score + teamAr[i].game3Score;

cout << teamAr[i].schoolName << setw(9) << teamAr[i].teamName << setw( 7);
cout << teamAr[i].game1Score << setw(4) << teamAr[i].game2Score <<setw(4);
cout << teamAr[i].game3Score << setw(4) << total << endl;
sub ++;
if (sub%4 == 0)
cout << endl;
}
}

/*********************************************************************
This function builds the array. It gets the information from the other
program and makes an array with structures as the types. It has the teaminfo
team array as its argument, and returns the number of valid teams.
**********************************************************************/

int buildArray(teamInfo teamAr[])
{
ifstream inFile;
int i;
teamInfo aTeam;

inFile.open ( "binary_teams" );

if ( inFile.fail() )
{
cout << "input file did not open";
exit(0);
}

i = 0;

inFile.read( (char *) &aTeam, sizeof(aTeam) );

while (inFile)
{
teamAr[i] = aTeam;

i++;

inFile.read( (char *) &aTeam, sizeof(aTeam) );
}

return i;
}

Way too long and un-formatted. Always wrap your code.

And when you define the function calcstats, the signature is not the same as the prototype.

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
157
158
159
160
161
162
163
164
165
/*********************************************************
CSCI 240 Program 8 Fall 2011

Programmer:

Section:
TA:

Date Due: 11/11/2011

Purpose: This is the second part of the assignment, that requires the building
of arrays to put together the structures of the team information.
**********************************************************/


#include <iostream>
#include <iomanip>
#include <fstream>

#define MAXTEAMS 48

using namespace std;

struct teamInfo
{
char schoolName[20];
char teamName[20];
int game1Score;
int game2Score;
int game3Score;
};

void calcStats(teamInfo[], int, double, double, double, int, int);
void printArray(teamInfo[], int);
int buildArray(teamInfo[]);

int main()
{
teamInfo teamAr[MAXTEAMS];
int teamcount, game1, game2, game3, totscore, loclow, lochigh;
double avgGame1, avgGame2, avgGame3;

teamcount = buildArray(teamAr);

printArray( teamAr, teamcount);

calcStats( teamAr, teamcount, &avgGame1, &avgGame2, &avgGame3, &lochigh, &loclow);

cout << "Tiddly-Winks Tournament Statistics\n";
cout << "----------------------------------";
cout << "Average Game 1 Score\t" << avgGame1 << endl;
cout << "Average Game 2 Score\t" << avgGame2 << endl;
cout << "Average Game 3 Score\t\n" << avgGame3 << endl;
cout << "Highest Scoring Team\t" << teamAr[lochigh].teamName << endl;
cout << "Lowest Scoring Team\t" << teamAr[loclow].teamName << endl;

system("pause");
return 0;
}

/********************************************************************
This function is used to calculate various stats from the tournament. It
the array, the count of teams, the averages of the games, and the location
of the highest and lowest scores as its arguments
*********************************************************************/

void calcstats (teamInfo teamAr[], int teamcount, double &avgGame1, double &avgGame2,
double &avgGame3, int &lochigh, int &loclow)
{
int i;
double sum1 = 0.00, sum2 = 0.00, sum3 = 0.00;

int temphigh,templow, total;

for (i == 0; i < teamcount; i++)
{
sum1 = sum1 + teamAr[i].game1Score;
sum2 = sum2 + teamAr[i].game2Score;
sum3 = sum3 + teamAr[i].game3Score;

total = teamAr[i].game1Score + teamAr[i].game2Score + teamAr[i].game3Score;

if ( total > temphigh)
{
temphigh = total;
lochigh = i;
}

if ( total < templow)
{
templow = total;
loclow = i;
}

}

avgGame1 = sum1 / teamcount;
avgGame2 = sum2 / teamcount;
avgGame3 = sum3 / teamcount;

}

/********************************************************************
This function totals up the score of all three games, and also displays all
of the information gathered in the tournament by printing the array. It has
the teaminfo array and number of teams as its arguments.
********************************************************************/

void printArray (teamInfo teamAr[], int teamcount)
{
int i, total, sub = 0;
cout << "\t\tBig 9 Conference Tiddly-Winks Tournament\n\n";
cout << "School Name\t" << "Team Name\t" << "Game 1 " << "Game 2 ";
cout << "Game 3 " << "Total Score\n";
cout << "--------------------------------------------------------\n\n";
for (i == 0; i < teamcount; i++)
{
total = teamAr[i].game1Score + teamAr[i].game2Score + teamAr[i].game3Score;

cout << teamAr[i].schoolName << setw(9) << teamAr[i].teamName << setw( 7);
cout << teamAr[i].game1Score << setw(4) << teamAr[i].game2Score <<setw(4);
cout << teamAr[i].game3Score << setw(4) << total << endl;
sub ++;
if (sub%4 == 0)
cout << endl;
}
}

/*********************************************************************
This function builds the array. It gets the information from the other
program and makes an array with structures as the types. It has the teaminfo
team array as its argument, and returns the number of valid teams.
**********************************************************************/

int buildArray(teamInfo teamAr[])
{
ifstream inFile;
int i;
teamInfo aTeam;

inFile.open ( "binary_teams" );

if ( inFile.fail() )
{
cout << "input file did not open";
exit(0);
}

i = 0;

inFile.read( (char *) &aTeam, sizeof(aTeam) );

while (inFile)
{
teamAr[i] = aTeam;

i++;

inFile.read( (char *) &aTeam, sizeof(aTeam) );
}

return i;
}

ico
Last edited on
Thanks, but that did not fix my problem. I am still getting the same error code. Also do you mean my code is too wide when you say wrap my code?
No i'm saying that it is easier to read if it is wrapped. reserved words are blue, line numbers, etc.
I see, I still can not figure out what my error is here. Also, for future reference how do I do that? This is my first time posting on here.
This calcStats( teamAr, teamcount, &avgGame1, &avgGame2, &avgGame3, &lochigh, &loclow); calls the function with pointers to double. &avgGame1 is a pointer. Drop that '&'
line 67 need to capitalize the "s"

void "calcstats"

should be "void calcStats"
Topic archived. No new replies allowed.