while loops to get information from a file

Hi, I'm having an issue with using a while loop to pull the data from a file. The files I created are very simple. I have a list of 7 names in the first file and the numbers 1 through 7 in the second. When I run what I have below it skips every other name starting with the first file and doesn't seem to be pulling information at all from the second file. Nothing I do seems to fix these problems. I tried searching this forum but I couldn't find anyone else having this issue. What am I doing wrong?

EDIT: I figured out part of my problem. It doesn't skip names now but I'm still not getting values from the second file.

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
#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main()
{
	
	ifstream inputFile1, inputFile2;
	string name;
	int sum = 0;
	double number = 1, grossPay;
	
	inputFile1.open("Employee.dat");
	inputFile2.open("Employee.rpt");

	while (inputFile1 >> name)
	{
		cout << name << endl;

		inputFile2 >> number;
		grossPay = number * 10;
		cout << grossPay << endl;
		
		sum++;
	}

	inputFile1.close();
	inputFile2.close();

	cout << endl << endl << "Ran a total of " << sum << " times.\n\n";






	return 0;
}
Last edited on
Topic archived. No new replies allowed.