OK, so im making some progress here!!! My assignment is to open and read from a txt file ("GradeFile.txt") with 3 rows of data. Each row of data represents a different type of assignment (ie. Homework, Exams & Programs) Each row to consist of:
1. # of Assignments (ie. 3)
2. Total # of possible points (ie. 300)
3. A groups of grades that corresponds to # of Assignments (ie. 90 90 90)
4. A number that represents the weighted GPA of each assignment type (ie. .60)
The text file would look something like this:
3 300 90 90 90 .60
4 400 90 90 90 90 .25
5 500 90 90 90 90 90 .15
I can get the first line to read correctly but the ".6" is hard coded in and I need it to be a variable. So my questions are:
Why isn't it working for the next line?
Why is it not looping 3 times?
and
How do I make the decimals (weighted GPA) a variable? I'm trying to assign the decimal to "Weight". I just cant seem to get it in the right place, so I just took it out.
I hope I have explained it ok...
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
|
#include <iostream>
#include <fstream>
using namespace std;
//function declarations
int PerformFileOperations();
int main()
{
cout << "Welcome to the GradeCaculator Deluxe." << endl;
PerformFileOperations();
system ("pause");
return 0;
}
//////////////PerformFileOperations
int PerformFileOperations()
{
int NoOfGrades;
int TotalPtsAllowed;
int Grades;
int Weight;
int index;
int count;
int Average;
ifstream DataFile;
DataFile.open("GradeFile.txt");
if (!DataFile)
{
cout << "File Failed to open...Program terminated" << endl;
return 1;
}//end if
cout << "Average GPA" << endl;
count = 0;
DataFile >> NoOfGrades >> TotalPtsAllowed;
while (DataFile)
{
count++;
//cout << "Homework::" << endl;
Average = 0;
index = 0;
while(index < NoOfGrades)
{
DataFile >> Grades;
index++;
Average = Average + Grades;
}
//cout << Average;
cout << " " << int(Average * .5) << " " << (int(Average * .5) * .6) << endl;
DataFile >> NoOfGrades >> TotalPtsAllowed;
}
return 0;
}//end PerformFileOperations
|