Hi, I kind of need help with my homework. I already have a code but it doesn't seem to work. I'm confused about the parameters I put. I don't know which part I actually messed up. I don't know what else to do. Thank you so much in advance for your help :]

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

//Function Prototypes
float gPACalculation(char cGrade);
string honorsDistinction(float fGPA);
void summaryInformation(float fGPA, string sHonorsDistinction);

//Declare Constants
const int SENTINEL = 0;

int main ()
{
	//Declare Variables
	ifstream inFile;				//input file
	ofstream outFile;				//output file
	char cGrade =' ';				//grades
	float fGPA = 0.0;				//GPA
	int nTotalGradePoints = 0;		//Total points
	int nCounter = 0;				//counter
	string sHonorsDistinction = "";		//honors distinction
	string sStudentID = "";				//student id
	int nPointsEquivalent = 0;			//equivalent points
	int nNumberOfGrades = 0;			//number of grade

	
	inFile.open("StudentData.txt");		//open input file

	if (inFile)
	{
		outFile.open("SummaryStudentData.txt");  //open output file

		inFile >> sStudentID;
		
		inFile >> cGrade;			//get grades from input file
	
		fGPA = gPACalculation (cGrade);	//call GPA calculation function		

		sHonorsDistinction = honorsDistinction(fGPA);     //call HonorsDistinction function

		summaryInformation(fGPA, sHonorsDistinction);

		outFile.close();	//closes output file

		cout << "Program executed successfully." << endl;		//prints success on the screen

		cout << "Refer to SummaryStudentData.txt file for output." << endl;	//prints refer to the screen
	}
	
	else
		{
		cout << "Couldn't open StudentData.txt." << endl;

		cout << "Program terminated." << endl;
		}
	
	system("pause");

	return 0;
}

float gPACalculation(char cGrade)
{
	int nPointsEquivalent = 0;
	int nTotalGradePoints = 0;
	int nCounter = 0;
	ifstream inFile;
	float fGPA = 0.0;

	while (!inFile.eof())       //while loop not at the end of the input file
		{
			nTotalGradePoints = 0;			//set total number of points to 0

			nCounter = 0;			//set counter to 0
			
			inFile >> cGrade;		//get grades from input file
		}
	
	if (cGrade == 'A')	//If statement to determine points
	
		nPointsEquivalent = 4;	//Points for A

	else if (cGrade == 'B')

		nPointsEquivalent = 3;	//Points for B

	else if (cGrade == 'C')
	
		nPointsEquivalent = 2;	//Points for C

	else if (cGrade == 'D')

		nPointsEquivalent = 1;	//Points for D

	else if (cGrade == 'F')

		nPointsEquivalent = 0;	//Points for F

	fGPA = nTotalGradePoints / nCounter;

	return cGrade;

}

string honorsDistinction(float fGPA)
{
	//declare variables
	string sHonorsDistinction = " ";
	
	if (fGPA > 3.7)		//if statement that determines the honor distinction of the equivalent GPA
		
		sHonorsDistinction = "Summa Cum Laude";		//prints summa cum laude
	
	else if ((fGPA < 3.7) && (fGPA > 3.4))
	
		sHonorsDistinction = "Magna Cum Laude";		//prints magna cum laude

	else if ((fGPA < 3.4) && (fGPA > 3.1))
		
		sHonorsDistinction = "Cum Laude";			//prints cum laude

	return sHonorsDistinction;				//returns honor distinction
}	

void summaryInformation(float fGPA,string sHonorsDistinction)
{
	//declare variables
	ifstream inFile;				//input file
	ofstream outFile;				//output file
	string sStudentID = "";

	inFile >> sStudentID;

	outFile << "Summary of Student GPA's and Honors" << endl;
	outFile << endl;
	outFile << sStudentID << fGPA << sHonorsDistinction << endl;

	return;

}
k3na26
Deleted Member

It would help to know what kind of errors you are getting and what methods actually work

Maybe you want to add the total points that the student has scored.

Maybe you dont want to keep resetting the variable which is supposed to keep track of how many grades the student has got

first error that comes up is it doesn't read/open the student data file, the next one is it doesn't calculate the gpa. :) thanks

Well, if it doesn't open the file, how can it calculate the data?

Where did you save the file?
Where is the program looking for the file?
Make sure they are the same place.

Well, if it doesn't open the file, how can it calculate the data?

Where did you save the file?
Where is the program looking for the file?
Make sure they are the same place.

the file was saved on my desktop,same as the project. I think I missed something on my main function but I can't figure out what it is. I'm sorry I'm kinda new to this and I don't know much about c++. thankyou :]

There maybe an issue with file paths. The solution to this problem is

1. Write a sample program to create a file. Give the file a weird name. Say aabbccddeeffgghh.txt.
2. After you create the file, exit the program and then use the search function to locate the file. From now one keep the file SummaryStudentData.txt in that folder.

Another option is to use absolute file names as opposed to relative file names

for this simple thing why are u exragatting too much

Comments
And for this simple thread, why are you posting useless stuff? Also, you bump an one year old thread...
This article has been dead for over six months. Start a new discussion instead.