Weird issues

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

using namespace std;

void openFiles(ifstream& inData, ofstream& outData);

void initialize (int& countFemale, int& countMale, float& sumFemaleGPA, float& sumMaleGPA, ifstream inData);

void sumGrades(float& sumFemaleGPA, float& sumMaleGPA, ifstream inData);

void averageGrade (float sumFemaleGPA, float sumMaleGPA, int countFemale, int countMale, float& maleAVG, float& femaleAVG);

void printResults(float femaleAVG, float maleAVG, ofstream outData);

int main(int argc, char *argv[])
{ cout << "***********************************\n"
"* john doe *\n"
"* Project 8 *\n"
"***********************************\n\n";



ifstream inData;
ofstream outData;
int countFemale, countMale;
float sumFemaleGPA, sumMaleGPA, maleAVG, femaleAVG;

openFiles(inData, outData);

initialize(countFemale, countMale, sumFemaleGPA, sumMaleGPA, inData);

averageGrade(sumFemaleGPA, sumMaleGPA, countFemale, countMale, maleAVG, femaleAVG);

printResults(femaleAVG, maleAVG, outData);

inData.close();
outData.close();


system("PAUSE");
return EXIT_SUCCESS;
}


//Open Input & Output files.
void openFiles(ifstream& inData, ofstream& outData)
{
inData.open("studentGPA.txt");
outData.open("averageGPA.txt");

outData << fixed << showpoint << setprecision(2);
}

// Initializes Variables
void initialize (int& countFemale, int& countMale, float& sumFemaleGPA, float& sumMaleGPA, ifstream inData)
{ countFemale = 0; countMale = 0; sumFemaleGPA = 0; sumMaleGPA = 0;

char gender, grade;
float temp;

sumGrades(sumFemaleGPA, sumMaleGPA, inData);

while(!inData.eof())
{
inData >> gender >> grade >> temp;
if(gender == 'f')
countFemale++;
else
countMale++;
}


}

// Finds the sum of the GPAs.
void sumGrades(float& sumFemaleGPA, float& sumMaleGPA, ifstream inData)
{ char gender, grade;
float temp;

while(!inData.eof())
{inData >> gender >> grade >> temp;

if(gender == 'f')
sumFemaleGPA += temp;
else
sumMaleGPA += temp;
}
}
//finds the average gpas
void averageGrade(float sumFemaleGPA, float sumMaleGPA, int countFemale, int countMale, float& maleAVG, float& femaleAVG)
{
femaleAVG = sumFemaleGPA / countFemale;
maleAVG = sumMaleGPA / countMale;
}
//
void printResults(float femaleAVG, float maleAVG, ofstream outData)
{
outData << "The average female grade point average is: " << femaleAVG << endl;
outData << "The average male grade point average is: " << maleAVG << endl;

}





it does not compile in bloodshed.... any help??
Last edited on
Please edit your post and add code tags, and provide the errors your compiler emitted.
closed account (S6k9GNh0)
cout << "***********************************\n" "* john doe *\n" "* Project 8 \n" "***********************************\n\n";

I learned today that you can use this format with cout.
Last edited on
That's not cout exactly, it's just the pre-processor or compiler (don't remember which) will automatically concatenate strings like that together for you.
I'm not sure what you mean by code tags. When I compile it opens up a file that I never call nor open. I think it is called ios_base.h or something like that. If you just copy and paste it into bloodshed it does this on an system I have never used a .hfile
Topic archived. No new replies allowed.