The point of the program is to read from the file and then output to the other file, we HAVE to use an array as well as a function to do this.
The problem I am running into is well... several problems.

When I try to run the program I either get "cannot access private member declared in class which I fixed by placing an & next to ifstream, but that caused the error unexpected character... someone help please I am sure it is something simple but I seem to be missing it big time.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

void Read_Data (ifstream, string, double, double, double, double, double);


int _tmain(int argc, _TCHAR* argv[])
{


	string name[50]={};
	double midterm[5]={};
	double final[5]={};
	double assignment1[5]={};
	double assignment2[5]={};
	double assignment3[5]={};
	ifstream infile;
	ofstream outfile;
	
	infile.open ("grades.txt");
	outfile.open ("report.txt");
	if (!infile)
	{
		cout << "Error: Cannot open file grade.txt." << endl;
		exit (1);
	}
	if (!outfile)
	{
		cout << "Error: Cannot open file report.txt." << endl;
		exit (1);


	}

		outfile <<"Dr. David Smith, Associate Professor" << endl;
		outfile << "Blue Ridge Community College" << endl;
		outfile << "Name"<< setw(15) << "Midterm" << setw(9) << "Final" << setw(9) << "Asng1" <<setw(9) << "Asng2" <<setw(9) << "Asng3" << setw(9) << endl;

		
		Read_Data (infile, name[50], midterm[5], final[5], assignment1[5], assignment2[5], assignment3[5]);

	outfile << name << midterm << final << assignment1 << assignment2 << assignment3;

	return 0;
}

void Read_Data(ifstream& infile, string name[50], double midterm[], double final[], double assignment1[], double assignment2[], double assignment3[])
	
{
	
	int i;
	for (i=0; i<10; i++);

	infile >> name[i] >> midterm[i] >> final[i] >> assignment1[i] >> assignment2[i]>> assignment3[i];


	return 0;	
}

Your infile >> name >> midterm...etc won't work because you haven't declared a struct. What this is supposed to do is work it's way through all the elements in the array starting at 0, and display them.

Your infile >> name >> midterm...etc won't work because you haven't declared a struct.

Declaring a struct has nothing to do with the problem.

Instead, you've declared arrays that can hold 50 names, but only 5 of everything else. Then your Read_Data() function tries to read 10 entries into those arrays. Also, you shouldn't specify the length of the names[] array at line 51, since you don't need to specify the length of any of the others.

Finally, since you loop over input lines to fill your arrays, you need to loop over your arrays to write output lines! Replace line 46 with a call to a Write_Data() function, which should look similar to your Read_Data() function (except passing an ofstream& as the first parameter, and changing the >>'s to <<'s, and possibly adding "<< endl").

you need to change your function decleration on line 8 to

void Read_Data(ifstream &, string[], double[], double[], double[], double[], double[]);

Good catch, NathanOliver, thanks!

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.