How to read the number from text.txt

Hello everyone,
I'm a new C++, and I have a question that needs to help.
Here is my assignment:

Bailey M CC 68
Harrison F CC 71
Grant M UN 75
Peterson F UN 69
Hsu M UN 79
Bowles M CC 75
Anderson F UN 64
Nguyen F CC 68
Sharp F CC 75
Jones M UN 75
McMillan F UN 80
Gabriel F UN 62

M F : MALE, FEMALE
CC : Community College
UN : University

+ I have been successful how to make the output for all of them, but I'm really stuck how to get those number to calculate the average from that text.txt using fstream
+ Also in the output. Please help me how to calculate the average of male, female using fstream.
+ Here is my code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;

int main()
{
string reply;
string inputFileName;
string line;
int count;
int number;
double total;
ifstream inputFile;

cout << fixed << showpoint << setprecision(2);
cout << "Please input your file name: ";
getline(cin,inputFileName);

inputFile.open(inputFileName.c_str());

if (!inputFile.is_open()) {
cout << "Unable to open input file." << endl;
cout << "Please press enter to continue...";
getline(cin, reply);
exit(1);
}

while (inputFile.peek() !=EOF) {
getline(inputFile, line);
cout << line << endl;
}

inputFile.clear();
inputFile.seekg(0);


cout << "End of file reached" << endl;


inputFile.close();
cout << "Please press enter to continue...";
getline(cin, reply);
return 0;
}

I really appreciate for everything that you help me. Thank you so much :)
Last edited on
Topic archived. No new replies allowed.