compile error (expected primary expression)


Hello everybody, my problem is that I am receiving a "expected primary expression before ')' " message when I try to compile my proggram. Could anyone point out what I'm doing wrong. The error comes up in int main() when I try to call other functions.









#include <iostream>
#include <iomanip>
#include <math.h>
#include <fstream>
using namespace std;

struct persons
{
int studentID;
double programAvg;
double testAvg;
};

const int MAXSIZE = 20;

persons student[MAXSIZE];

int buildAr( persons []);
void displayAr( persons [], int );






int main()
{
persons student [MAXSIZE];
int i,
count;

buildAr (persons);
displayAr (persons);











system("pause");
return 0;

}
/***************************************************************
Function: buildAr
Use: opens a file to receive data used to fill the student ID number, program and test averages arrays
Arguments: the student array
Returns: number of students in an array
***************************************************************/

int buildAr( persons[]) //this function fills all 3 arrays and returns student count
{

int count = 0;

ifstream inFile;

//inFile.open( "C:\\Users\\Owner\\Desktop\\averages.txt" );

inFile.open( "averages.txt" );

if ( inFile.fail() )
{
cout << "open for averages.txt failed";

exit (1);
}

inFile >> student[count].studentID;


while ( inFile ) //this loop reads all values from the file and places them in
{ //in their corresponding array

inFile >> student[count].programAvg;
inFile >> student[count].testAvg;

count++;

inFile >> student[count].studentID;

}


inFile.close();

return count; // student count//
}
/*****************************************************************
Function: displayAr
Use: display the students' ID numbers, their program and test averages, also calculate and display overall averages
Arguments: student array and student count
Returns: nothing
***************************************************************/
void displayAr( persons [], int count ) //function to sort arrays//

{

int i;
double overallAvg;

cout << "Student ID Program Average Test Average Overall Average\n";
cout << "-------------------------------------------------------------------\n";

for (i = 0; i < count; i++)
{
overallAvg = (student[i].programAvg * 0.4 ) + ( student[i].testAvg * 0.6 ); //equation for overall average

cout << student[i].studentID << setw(18) << student[i].programAvg << setw(19) << student[i].testAvg << endl;
}

}
Last edited on
1
2
3
persons student[MAXSIZE];
int buildAr( persons []);
buildAr (persons);
You declare an array of persons called student, define a function that takes an array of persons, but line 3 isn't giving them an array, you put in a data type, not a variable.
thank you so much, that fixed that problem, but now when I run the program it seems to go in a endless loop and my program crashes, do you have any idea what may be causing this? Also the numbers that were displayed makes no sense, there are a bunch of zeros and alot of exponents.
Last edited on
i figured it out. the problem was in calling the function buildAR. I switched it to count = buildAr()
Topic archived. No new replies allowed.