Passing initializations to main()

Hi. I am new to C++. Basically we have this exercise in our book. Here are the instructions:

6. For research purposes and to better help students, the admissions office of
your local university wants to know how well female and male students
perform in certain courses. You receive a file that contains female and male
student GPAs for certain courses. Due to confidentiality, the letter code f is
used for female students and m for male students. Every file entry consists of
a letter code followed by a GPA. Each line has one entry. The number of
entries in the file is unknown. Write a program that computes and outputs
the average GPA for both female and male students. Format your results to
two decimal places. Your program should use the following functions:
a. Function openFiles: This function opens the input and output files,
and sets the output of the floating-point numbers to two decimal places
in a fixed decimal format with a decimal point and trailing zeros.
b. Function initialize: This function initializes variables such as
countFemale, countMale, sumFemaleGPA, and sumMaleGPA.
c. Function sumGrades: This function finds the sum of the female and
male students’ GPAs.
d. Function averageGrade: This function finds the average GPA for
female and male students.
e. Function printResults: This function outputs the relevant results.
f. There can be no global variables. Use the appropriate parameters to pass
information in and out of functions.


Here is the code I have written:
#include<iostream>
#include<fstream>
#include<iomanip>

using namespace std;


void openFiles()
{
ifstream input;
ofstream output;
input.open("list.txt");
output.open("update.txt");
setprecision(2);
output<<fixed << showpoint;

}

void initialize()
{
double countFemale=0;
double countMale=0;
double sumFemaleGPA=0;
double sumMaleGPA=0;


}

double sumGrades(double GPA)
{
return GPA;


}

double averageGrade(int count, double sum)
{
return sum/count;

}

int main()
{

char gender;
double sumMaleGPA=0; //
double sumFemaleGPA=0; //
int countMale=0; //
int countFemale=0; //
double GPA=0;

do
{
cin >> gender >> GPA;
if (gender='m')
{ countMale+=1;
sumMaleGPA+=sumGrades(GPA);
}
else
{ countFemale+=1;
sumFemaleGPA+=sumGrades(GPA);
}



}while(!input.eof()) ;
//the input is not recognized of course, since main does not know what input // //is.


cout << "The average for males is: ";
cout << averageGrade(countMale, sumMaleGPA);
cout << "The average for females is: ";
cout << averageGrade(countFemale, sumFemaleGPA);

return 0;


}


I am not sure of the ones with slash. I can't seem to find a way to pass the initializations made by the initialize() and openFiles() to the main function. Any suggestions.

Also, any tips for improving the program?
Topic archived. No new replies allowed.