I CAN NOT GET THIS TO WORK I THINK IT IS GOING WRONG IN THE INDATE FILES

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;

void calculateAverage (ifstream&, ofstream&, double&);
char calculateGrade (double);
int main ()
{
char grades [15];
double avg, average=0;
int count=0;
string name;

ifstream inFile;
ofstream outFile;
cout << "\n\tProgram that works with files and functions.";
cout << "\n\n\tEnter the input file name : ";
cin >> grades;
inFile.open("G:\\grades.txt");

if (!inFile.is_open("G:\\calGrades.txt"))
{
	cout << "\n\n\tError with the input file";
		exit (0);
}
	cout << "tEnter the output file name :";
	cin >> "G:\\calGrades.txt";
	outFile.open ("G:\\calGrades.txt");

	if (!outFile.is_open("G:\\calGrades.txt"))
{
	cout << "\n\n\tError with the input file";
		exit (0);
}
	outFile << fixed;
	outFile .presision(2);
		outFile << "Student		Test1	Test2	Test3	Test4	Test5	Average	Grade";
		outFile << endl;

	while (true)
	{
		inFile >> name;
		
		if (!inFile)
			break;

		outFile << setw(10);
		outFile << left;
		outFile << name;
		calculateAverage (inFile, outFile, avg);
		outFile << setw(10);
		outFile << right;
		outFile << avg;
		outFile << setw(6);
		outFile << right;
		outFile << calculateGrade(avg);
		outFile << endl;
		count ++;
		average += avg;
	}

	average /= count;
	outFile << endl << "Class Average = " << average;
	inFile.close ("G:\\grades.txt");
	outFile.close ("G:\\calGrades.txt");
	return 0;
}

void calculateAverage (ifstream& in, ofstream& out, double& std)
{
	int score;
	double avg = 0;

		for (int i=0; i<5; i++)
		{
			in >> score;
 			out << setw(7) << right << score;
			avg += score;
		}
		avg /= 5.0;
}
char calculateGrade (double myAvg)
{
	if ( myAvg < 60)
		return 'F';
	else 
		if ( myAvg < 70)
			return 'D';
		else 
			if (myAvg < 80)
				return 'C';
			else 
				if (myAvg < 90)
					return 'B';
				else 
					return 'A';
}

Edited 7 Years Ago by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

lines 24 and 33: is_open() does not take any parameters.

line 30: you can not put string literal on that line. You have to replace that string literal with a variable name, something similar to what you did on line 21.

There are probably other errors -- I stopped reading your code there.

Edited 7 Years Ago by Ancient Dragon: n/a

This article has been dead for over six months. Start a new discussion instead.