student's average grade c++ (simple question) :)

Hi , I'm working on a project were I have to build a program that read from a text file some student grades and calculate average and total average .I've done everything exept that I do not know why I'm getting (instead of total average ) a zero .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std ;


int main() {
	// Declaring the variables
	double Exam1 = 0 ;
	double Exam2 = 0 ;
	double Exam3 = 0 ;
	string name ;
	double AverageGrade = 0 ;
	double TotalAverage = 0 ;
	string letterGrade ;
	string data ;

	// the input file 
	ifstream input_file("students.txt") ;	

	// Checking if the input file exists. If he do not , the program stop
	if (input_file.fail()) {
		cout << "No input file found!" << endl ;
		system("pause") ;
		return 0;
	}
	
	cout << "Name" <<setw(15)<< "Exam-1" <<setw(15)<<"Exam-2" <<setw(15)<< "Exam-3"  <<setw(15)<< "average grades" <<setw(15)<< " letter grades" <<endl ; 
	

	  while (getline(input_file, data))
{
    if (data == "Name Exam-1 Exam-2 Exam-3") continue;
	  while (!input_file.eof()) {	
		// reading a number from the input file
		input_file >> name >> Exam1 >> Exam2 >> Exam3 ;
		double AverageGrade = (Exam1 + Exam2 + Exam3 )/3 ;
		double TotalAverage =(TotalAverage + AverageGrade)/6;
		if (AverageGrade >=90  )
			 {   
	         letterGrade = "A";
			 }
		 else if (AverageGrade >=80 ) 
		    {
			 letterGrade = "B";
		    }
		else if (AverageGrade >=70) 
		    {
			 letterGrade = "C" ;
		    }
		 else if (AverageGrade>=60 ) 
		    {
			 letterGrade = "D" ;
		    }
		 else 
			 {
			 letterGrade = "F" ;
		    }   
	cout<< name <<setw(15)<< Exam1 <<setw(15)<<  Exam2 <<setw(15)<< Exam3 << setw(15)<< setprecision(4) <<  AverageGrade <<setw(15)<< letterGrade << endl ;
	  }
	  cout <<AverageGrade << endl ;
	  }
	  system("pause") ;
}

this is the input file
 Name        Exam-1   Exam-2   Exam-3
 J           78       90       88
 L           80       87       82
 S           60       58       78
 T           75       78       56
 C           95       90       92
 R           89       79       67
Last edited on
anyone?
Hi @yacinebenz,
try deleting the
key word "double" in
line 38,39 before
"AverageGrade","TotalAverage"
Thank's alot @eyenrique.
You are welcome!
lol @eyenrique I actually do not get right answers , I should normaly get 78.99 , but I get 13.06. Which mean that It only perform the calculation on the last value .
#include <limits> and do the loop as follows :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
file_in.ignore( numeric_limits<streamsize>::max(), '\n' ); // ignore the first line

while( file_in >> name >> exam1 >> exam2 >> exam3 ) {
    averageGrade = (exam1 + exam2 + exam3) / 3;
    totalAverage = averageGrade / 6;

    if( averageGrade >= 90.0 )
        letterGrade = 'A';
    else if( /* */ )
        // ...
    // ...
    else
        letterGrade = 'F';

    // print
}


looping on eof() is a bad way
@yacinebenz lol,
i was looking just for
"syntax" errors but
there should be "logical"
mistakes, follow @nvrmnd
advices!
Topic archived. No new replies allowed.