could someone take a look at my code and tell me what is wrong with it. i cannot figure out why the program gives me an error message. it is supposed to print a table with the male and female students and their grades. any help is appreciated.
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
struct StudRec
{
int id;
char gender;
float score;
};
void ReadData (ifstream, StudRec &);
void DisplayTable (int, int, float, float);
void main ()
{
ifstream inData;
StudRec student;
int countBoys = 0.0, countGirls = 0.0;
float sumBoys = 0.0, sumGirls = 0.0;
float maleavg = 0.0, femaleavg = 0.0;
inData.open("A:\ScoreByGender.txt");
if (!inData)
cerr << "File cannot be found." << endl;
while (!inData.eof()){
ReadData(inData, student);
cout << endl << endl;
}
if (student.gender = 'M'){
countBoys ++;
sumBoys += student.score;
}
if (student.gender = 'F'){
countGirls ++;
sumGirls += student.score;
}
maleavg = sumBoys / countBoys;
femaleavg = sumGirls / countGirls;
DisplayTable (countBoys, countGirls, maleavg, femaleavg);
}
void ReadData (ifstream inData, StudRec &student)
{
inData >> student.id >> student.gender >> student.score;
}
void DisplayTable (int cntboys, int cntgrls, float mlavg, float fmavg)
{
cout << setw(15) << "number of students" << setw(15) << "average"
<< endl << setw(15) << "------------------" << setw(15)
<< "-------" << endl << "Boys" << setw(15) << setprecision(0)
<< cntboys << setw(15) << mlavg << endl << "Girls" << setw(15)
<< cntgrls << setw(15) << fmavg << endl;
}