issue opening txt file?

Im having an issue with some HW of mine, I can't get the program to access the employee.txt files and hours.txt

Problem
Assume there are two input files for a payroll program. The first contains the employee’s name (a string), id number (an integer) an hourly rate (a real number). The second contains the employee’s id number and hours worked (a real number). The records in the first file are ordered by name and the records in the second file are ordered by id number. If a person did not work during the current time period, there will be no record in the second file for that person. Write a file of payroll records to an output file for all employees. Each record should contain the employee name followed by # followed by the hours worked, hourly rate, and pay amount. Use a space as a separator between items in the output file. There should be a record in the output file for every person including those who did not work in that pay period.


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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Ch 8 Project.cpp 

#include "stdafx.h"
#include <fstream>		
#include <iostream>
#include <cstdlib>		
#include <map>
#include <string>
#include <string.h>
#include <cstdio>

using namespace std;

#define inFileEmp "employees.txt"	
#define inFileHour "hours.txt"		
#define outFile "payout.txt"		


void processHours(std::istream&, std::map<int, double>&);	

int main()
{
	ifstream eds;		
	ifstream hrds;		
	ofstream pds;		
	int id;
	double rate;
	double hours;
	string name;

	eds.open(inFileEmp);
	if (eds.fail())
	{
		cerr << "*** ERROR: Cannot open " << inFileEmp << " for input." << endl;
		
	}
	
	
	hrds.open(inFileHour);
	if (hrds.fail())
	{
		cerr << "*** ERROR: Cannot open " << inFileHour << " for input." << endl;
		
	}
	
	
	pds.open(outFile);
	if (pds.fail())
	{
		cerr << "*** ERROR: Cannot open " << outFile << " for output." << endl;
		
	}
	
	std::map<int, double> aIdToHours;
   	processHours(hrds, aIdToHours);

	
    	while(eds >> name >> id >> rate)
    	{
     		hours = aIdToHours[id];
     	 	pds << name << " " << id << " " << rate << " " << hours << " $" << hours*rate << std::endl;
    	}

   	
	
	eds.close();
	hrds.close();
	pds.close();


	system("pause");
	return 0;

	}



void processHours(std::istream& hrds, std::map<int, double>& oData)
{
 	 int id;
 	 double hours;
 	 while(hrds >> id >> hours)
  	{
   		 oData[id] = hours;
	}
}

Im having an issue with some HW of mine, I can't get the program to access the employee.txt files and hours.txt


Make sure they're in the same directory as the "payout.txt" you generated.
jeckel,

would you mind describing your data tables to me?
It seems as if you are separating the fields with a TAB- or at least that is working for me,
All , except for the NAME field in the Employees file.
No matter how I format "name" in the file or in my output (test) string, I can only get trash.

The INT "id" and the DOUBLE "rate" are being displayed on my screen fine,
just not the "name" field.

I was hoping to get this running and tested on my machine, but it won't get past the first pass of "processHours()" with not having that first field available,

Although, it IS ! odd that the program does get into that subrt'n without having a valid name available - AND with nothing at all in the "HOURS" file.







Topic archived. No new replies allowed.