Then there has to be something that breaks your code, either the input file or compiler optimization, because it works fine for me both on debug and release with the input file you mentioned in the beginning of the thread.
EDIT: Why don't you try the following code and reply with what output you get:
Code:
int main()
{
string name, majorname, coursename;
ifstream inData;
ofstream outData;
double gpa = 0, mgpa = 0, fgpa = 0, averagef = 0, averagem = 0;
int mcounter = 0, fcounter = 0;
char gender = 0, show_gender = '\0';
//char genderFromFile = 0;
//char m = 0;
inData.open("C:\\input.txt");
//outData.open("outData.txt");
cout << "Hello there, What is your name?" << endl;
getline(cin, name);
cout << "Welcome " << name << ".\n";
cout << "Please enter your degree your majoring in." << endl;
getline(cin, majorname);
cout << "What the name of the course your taking for your major " << majorname << " ?\n";
getline(cin, coursename);
cout << "What is your gender? Enter m for male or f for female." << endl;
cin >> show_gender;
//outData << "Person's name is " << name << ". And there degree major is " << majorname << ". The class course name for there degree major is " << coursename << ".\n";
while(inData >> gender >> gpa)
{
cout << "DEBUG INFO: gender = " << gender << ", gpa = " << gpa << endl;
if (gender == 'm')
{
mcounter++;
mgpa += gpa;
}
else if (gender == 'f')
{
fcounter++;
fgpa += gpa;
}
}
if (show_gender == 'm')
{
averagem = mgpa / mcounter; // Average GPA
cout << "The average for the male gpa is: " << averagem << endl;
}
else if (show_gender == 'f')
{
averagef = fgpa / fcounter; // Average GPA. Divide the total GPA by the number of entries found in the file.
cout << "the average for the female gpa is: " << averagef << endl;
}
_getch();
return 0;
}
I added debug info to see if your program screws up somewhere, so post the outpost from the console window.