same program as before. reads in a text file. in the text file there are males and females and scores for them.
I would like to calculate the average for all the scores for the males or females.
what would be the best way to go about this?
I am sure i would have to first find all the females and then add the scores up and didvide by the number of females. but not sure how to go about that?
output:Code:#include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { char name[25]; char gender; char code[5]; int score; int count = 0; char reply; ifstream infile; string myfile; //char process[200]; ifstream inputFile; cout << "Enter file name with the extension(Example: scores.txt): " << endl; cin >> myfile; inputFile.open (myfile.c_str(), ios::in); if(!inputFile) { cerr << "Can't open input file " << myfile << endl; cin >> reply; exit(1); } while(!inputFile.eof()) { inputFile >> name; count++; cout << name; inputFile >> gender; cout << gender; inputFile >> code; cout << code; inputFile >> score; cout << score << endl; //inputFile.getline(process,200); } } cin >> reply; return 0; }
M = male
F= female
CC = comunity college.
just to clarify
not sure why it's picking up the last F 62 thats from the last name Gabriel.Code:Enter file name with the extension(Example: scores.txt): scores.txt 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 F 62
thank you!



LinkBack URL
About LinkBacks



