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.
/ 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>
usingnamespace 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;
}