I NEED BIG HELP FOR employee Absent project:

I have a running code here. should really do the trick.
I am having trouble releasing the information being input by user to the "outputFile" I need it to be organized such as for example:
Employee ID: Employee absence:
1234 5
123 5

I was able to to output the info in the main function but not able to the others.

If anyone could help me with a flowchart too will do me a great big deal. This project is due in about 2 hours and i am not really good at flowcharts.

Any help please:

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

int employee_Number();
int daysNumber(int);
double average_abs(int, int);
int main()
{
	ofstream outputFile;
	outputFile.open("employeeAbsences.txt");
	int employeeNum_data = 0;
	int employeeId_data = 0; 
	int daysNumber_data = 0;
	double absAverage_data = 0.0;
	employeeNum_data = employee_Number();
	daysNumber_data = daysNumber(employeeNum_data);
	absAverage_data = average_abs(employeeNum_data, daysNumber_data);	

	outputFile << "The " << employeeNum_data << " employees were absent a total of " << daysNumber_data;
	outputFile << "\nThe average number of days absent is: " <<  absAverage_data;
	outputFile << "\nProgrammer: Tanguy Razafindragolo " << endl;
	outputFile.close();
	cout << endl;
	system("pause");
	return 0;
}
int employee_Number()
{
	int employeeNumber_1;

	cout << "Please enter the number of the employees in the company: ";
	cin >> employeeNumber_1;

	while (employeeNumber_1 < 1)
	{
		cout << "The number of employee must be greater than 0.";
		cout << "Please re-enter the number of employee.";
		cin >> employeeNumber_1;
	}
	return employeeNumber_1;
}

int daysNumber(int e)
{
	int employeeNumber_1 = e;
	int daysNumber_1;
	int total_days = 0;

	for (int i = 0; i < employeeNumber_1; i++)
	{
		ofstream outputFile;
		outputFile.open("employeeAbsences.txt");
		int employeeId;

		cout << "Please enter employee ID: ";
		cin >> employeeId;
		cout << "Please enter the number of days " << employeeId << "  was absent: ";
		cin >> daysNumber_1;

		outputFile << employeeId << endl;
		

		total_days += daysNumber_1;

		if (daysNumber_1 < 0)
		{
			cout << "The number of days must not be negative." << endl;
			cout << "Please re-enter the number of days absent: ";
			cin >> daysNumber_1;
		}
		outputFile.close();
	}


	
	return total_days;
}
double average_abs(int a, int b)
{
	int employeeNumber_1 = a;
	int total_days = b;
	double absAverage_1;

	absAverage_1 = total_days /employeeNumber_1;
	return absAverage_1;

}
Hello trazafin,

In main you open "employeeAbsences.txt" then open it again in the function "daysNumber". If you want to use this stream in "daysNumber" you will need to pass what you opened in main to the function, i.e.,
daysNumber_data = daysNumber(outputFile, employeeNum_data)
and in the function definition
int daysNumber(ofstream& outputFile, int e).

Then you will no longer need lines 53 and 54.

I will test this shortly, but I think this should work.

Hope that helps,

Andy
Hello trazafin,

The parts that needed fixed:

The proto types:
nt daysNumber(ofstream& outputFile, int);

In main
outputFile << "\nThe " << employeeNum_data << " employees were absent a total of " << daysNumber_data << " days."; //<--- Added "days" at the end.

The "daysNumber" function:
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
int daysNumber(ofstream& outputFile, int e)  // <--- Added first parameter.
{
	int employeeNumber_1 = e;
	int daysNumber_1;
	int total_days = 0;

	outputFile << "Employee ID:" << setw(20) << "Employee absence:" << std::endl;  // <--- Added this line.

	for (int i = 0; i < employeeNumber_1; i++)
	{
		//ofstream outputFile;
		//outputFile.open("employeeAbsences.txt");
		int employeeId;

		cout << "Please enter employee ID: ";
		cin >> employeeId;
		cout << "Please enter the number of days " << employeeId << "  was absent: ";
		cin >> daysNumber_1;

		outputFile << setw(6) << employeeId << setw(17) << daysNumber_1 << endl;  // <--- Added this line.


		total_days += daysNumber_1;

		if (daysNumber_1 < 0)
		{
			cout << "The number of days must not be negative." << endl;
			cout << "Please re-enter the number of days absent: ";
			cin >> daysNumber_1;
		}
		//outputFile.close();
	}

	return total_days;
}


This should be closer to what you want.

Hope that helps,

Andy
Topic archived. No new replies allowed.