Trouble pulling names/grades (seperate files) and printing to a third file? File is blank.

I'm trying to pull names from one file, grades from another, and printing both to a third file. I've done similar things before and even tried to reuse some code, but I cannot get it to work.

1. When I use "cout" instead of "outData" the only thing that prints is "Student Name:". The rest is blank. I tried this without using loops and arrays but couldn't get anything to work. I have 10 names and 5 grades for each so I thought it would be easier and less time-consuming to use them.

I'd appreciate any help or tips you can provide. I'm new to C++, just started learning it in Jan/Feb. Thanks!

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
 
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

//Variables:
string name1;



int main ()
{
	
	ifstream inData;
	ifstream inData2;
	ofstream outData;

	inData.open("Names.txt");
	inData2.open("Grades.txt");
	outData.open("FinalNote.txt");

	getline(inData, name1);

       outData <<"Student name:" << name1 << endl;
	   
       int number = 0;
	   const int size = 50;
	   double grade1[size];
	   
	   for (int j=0; !inData.eof(); j++)
		   {
			   inData >> grade1[j];
			   number++;
			};
	     
	  outData << "Grades:" << endl;

	   for (int i=0; i<5; i++)
		  {
			  outData << grade1[i]<<endl;

          }; 

      

      system("PAUSE");
	  
	return 0;
};
It's pretty much hard to see what is happening as there is no error-checking of any kind. Does the program terminate normally, rather than fail in some way?

Could you give samples of the contents of the two input files please.
I added an error-checking to the files:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
if (inData.is_open() )
	{ cout << "Names file opened successfully." << endl; }
	else 
	{ cout << "Error opening Names file." << endl;};

	if (inData2.is_open() )
	{ cout << "Grades file opened successfully." <<endl; }
	else 
	{ cout << "Error opening Grades file." << endl; };

	if (outData.is_open() )
	{ cout << "Output file opened successfully." << endl; }
	else
	{ cout << "Error opening output file." << endl;}; 



and I get errors for opening both of my input files. I have all my files saved in the same directory so I don't understand why they don't open?

The input files look like:
"Names" has ten names listed like this:
Nicole Smith
Jeanine Williams
Taryn Bakersfield

And the "grades" file has listed grades like this:
89 100 73 74 99
23 54 100 88 93
39 57 96 95 86
How did you save the files? Have you gone to the command line, cd into the proper directory and list the directory? Do the files by chance look something like "Grades.txt.txt"?

Thanks everyone for your help. I ended up deleting the files and recreating them. Somewhere along the way I was mixing up the paths to the file but couldn't find where. Deleting the old ones and making new ones seemed to help.
Topic archived. No new replies allowed.