My teacher gave use a project were we have to read a text from a file and then output some results. I have got C++ to read the text from file but I have to average out each persons test scores and then output them. I am not sure how to do this any help using c++ coding will be great.

#include <iostream>
#include <iomanip>                      //Include to recognize setw
#include <fstream>                      //Open the file 
#include <string>
using namespace std; 

int main() 
string names;
ifstream openfile ("students.txt");
if (openfile.is_open())
	while (openfile)
	getline (openfile, names);
	 cout << names << endl;

return 0;

The file that I am trying to read from has the following

Bill Clinton 92 64 91
George Bush 66 42 75
Ronald Reagan 50 50 56
Jimmy Carter 82 -5 91
Gerald Ford 118 64 88
Richard Nixon 90 90 93
Lyndon Johnson 78 90 68
John Kennedy 52 96 75
GW Bush -100 -45 -1000

This is the actual assignment
your program will first obtain the number of data lines, then in a
loop (count-controlled) it will read the data line for each student
and calculate the average score and letter grade for each student
as before. Your program should also calculate the class average.
For this, you need to add up the student averages in a "summing" variable
and divide that (after all student averages are added up) by the
class size.

Edited by Nick Evan: Added code-tags

7 Years
Discussion Span
Last Post by Ancient Dragon
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.