I'm having quite a difficult time with this program. I'm trying to write a program that calculates the average of the GPAs for male and female students. Each line of my file has an f or an m followed by a GPA. I have to use a sentinel controlled while loop, but I'm having a heck of a time. I'm not really sure what to do??
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
int main()
{
const int sentinel = -999;
ifstream inFile;
string grades;
int num;
int sum = 0;
int count = 0;
inFile.open("C:\\Ch5_GPAInput.txt");
getline(inFile, grades);
cout << "Line 1: Enter the numbers ending with " << sentinel << endl;
cin >> num;
while (num != sentinel)
{
sum = sum + num;
count++;
cin >> num;
}
cout << "Line 7: The sum of the " << count << " numbers is " << sum << endl;
if (count != 0)
cout << "Line 9: The average is " << sum / count << endl;
else
cout << "Line 11: No input." << endl;
inFile.close();
system("PAUSE");
return 0;