Student Average, initilization issue?

Keep getting an error that says testgrade1 is not initialized. On my input file, I have allowed the user to enter in the grade for test1 and test 2, but I only keep getting an error that states "testgrade1 has not been initialized. Can anyone tell me whats wrong with this code.
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
67
68
69
70
71
72
73
74
 

/ Student Average.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <conio.h>
#include <fstream>
//Declare a library for student names
#include <string>
#include <iostream>
using namespace std;
#include <iomanip>

int _tmain(int argc, _TCHAR* argv[])

{
	//********************************************************************START OF CODE**************************************************************

	//Declare Variable for names, two test grades, counter for number students, average of test
	string firstname;
	string lastname;
	double testgrade1;
	double testgrade2;
	int counter;
	counter=1;
	double testaverage;
	testaverage=(testgrade1+testgrade2)/2;

	// Open file2.txt 

	ifstream fin;
	fin.open("File2.txt");

	//In case, file doesnt open. Print out an error message

	if (!fin)
		{
			cout<<"Cannot open the input file" <<"\nProgram Terminates";
			
			//This return1 will exit the program due to error
			return 1;
	
		}
	
	//**************************************************CONSOLE OPEN*********************************************************************

	//Outputing data names that will be outputted on the screen. For instance, name, grades, letter grade
		cout<< " Student Statistics: " << endl <<endl;
		cout<< "Name\t" << "\tTest" << "\tAssignments" << "\tPoints" <<"\t  Numeric " <<"\tLetter ";
		cout<< endl << "\t\t Avg" << "\t   Avg"<< "\t\t\t    Grd" << "\t\t Grd ";
	

	//Outputting first name, last name on the screen;
		while (fin)
		{

			//Data is being entered in the input file
			fin>>firstname >> lastname;
			cout<< endl <<endl <<firstname <<lastname;
				
			//Enter in test grades
			
			fin>>testgrade1 >>testgrade2;
			
			
		
		}
	_getch();
	return 0;
}


 

Last edited on
Line 28.
ahh. Should have caught that. Thank you though :)
Topic archived. No new replies allowed.