hey guys i need some help with this input file program im getting input file invalid all the time i have no idea what to do. im supposed to create data files with data for up to 10 students and calculate their average from five perecentages i think i got everything down i just have to get the input file down
heres the problem:

Write 4 functions:
a) a void function to read in one line of data from the data file you have created and pass the data back to the calling function.
b) a value returning function to accept the 5 marks out of 100, calculates the average mark, and returns the average mark.
c) a value returning function that accepts the average mark and returns a string with “Pass” if the mark is >= 50 otherwise “Fail”.
c) a void function to write out one line of data to an output file which includes the original data plus the average (accurate to 2 decimal places) and Pass or Fail

feel free to add any suggestions to make this program better

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

void studentinfo(ifstream&, int& studentid, string& studentnamelast, string& studentnamefirst, int& gr1, int& gr2, int& gr3, 
int& gr4, int& gr5); 

double CalculateAverageGrade(int gr1, int gr2, int gr3, int gr4, int gr5); 

string pass(double);

void writeData(ofstream&, int studentid, string studentnamelast, string studentnamefirst, int gr1, int gr2, int gr3, int gr4, int gr5, double avg, string passfail);

void writeHeading(ofstream&);

int main() 
{ 
string studentnamefirst, studentnamelast, inputFileName, outputFileName, passfail;  
int gr1, gr2, gr3, gr4, gr5, studentid;
double avg; 
int counter=0;

	cout<<"Please enter input file name: ";
	cin>>inputFileName;

	cout<<"Please enter output file name: ";
	cin>>outputFileName;

	ifstream in_stream("infile.txt");
	if (in_stream.fail())
	{
		cout << "Input file opening failed.\n";
		exit(1);
	}
	ofstream out_stream("outfile.txt");
	if (out_stream.fail())
	{
		cout << "Output file opening failed.\n";
		exit(1);
	}

writeHeading(out_stream);

while(!in_stream.eof())
{
		studentinfo(in_stream, studentid, studentnamelast, studentnamefirst, gr1,gr2,gr3, gr4, gr5);
		counter++;
		if(counter>=10){break;}
		avg=CalculateAverageGrade(gr1, gr2, gr3, gr4, gr5);
		passfail=pass(avg);
		cout.setf(ios::fixed);
		cout.setf(ios::showpoint);
		cout.precision(2);
		cout<<studentid<<setw(10)<<studentnamelast<<setw(12)<<studentnamefirst<<setw(8)<<gr1<<setw(8)<<gr2<<setw(8)<<gr3<<setw(8)<<gr4<<setw(8)<<gr5<<setw(8)<<avg<<setw(8)<<passfail<<endl;
		writeData(out_stream, studentid, studentnamelast, studentnamefirst, gr1, gr2, gr3, gr4, gr5, avg, passfail);
}

return 0; 
} 


void studentinfo(ifstream& in_stream, int& studentid, string& studentnamelast, string& studentnamefirst, int& gr1, int& gr2, int& gr3, 
int& gr4, int& gr5) 
{ 
in_stream >> studentid >> studentnamelast >> studentnamefirst >> gr1 >> gr2 >> gr3 >> gr4 >> gr5;
} 

double CalculateAverageGrade(int gr1, int gr2, int gr3, int gr4, int gr5) 
{ 
return (gr1 + gr2 + gr3 + gr4 + gr5) / (5.00);
} 

string pass(double avg)
{
	if(avg>=50)
	{
		return "Pass";
	} 
	else
	{
		return "Fail";
	}
} 

void writeData(ofstream& out_stream, int studentid, string studentnamelast, string studentnamefirst, int gr1, int gr2, int gr3, int gr4, int gr5, double avg, string passfail)
{
	out_stream<<left<<setw(10)<<studentid<<setw(10)<<studentnamelast<<setw(12)<<studentnamefirst<<setw(8)<<gr1<<setw(8)<<gr2<<setw(8)<<gr3<<setw(8)<<gr4<<setw(8)<<gr5<<setw(8)<<avg<<setw(8)<<passfail<<endl;
}

void writeHeading(ofstream& out_stream)
{
	out_stream<<left<<setw(10)<<"Student#"<<setw(10)<<"Last Name"<<setw(12)<<"First Name"<<setw(8)<<"Mark 1"<<setw(8)<<"Mark 2"<<setw(8)<<"Mark 3"<<setw(8)<<"Mark 4"<<setw(8)<<"Mark 5"<<setw(8)<<"Average"<<setw(8)<<"Pass/Fail"<<endl;
}

See line 32. You previously asked for the input filename but hardcoded it at line 32. Also check the file system to see that its in the current working directory (where the *.exe program runs). If not then you have to specify the full path on line 32. Finally, if the file name contains spaces, such as Program Files then line 27 won't work -- you have to use getline() in that case.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.