I'm writing a program that shows the average leaves taken by an employee. I'm trying to figure out what the problem is with the order. I've been told that there's a return that's blocking the program from displaying the first part, but I can't find what one is doing it.
When I run it, all that is showing is "Average leaves taken by an employee are: 0"
All in all, I just want this program to allow the user to leave input before displaying the answer.
#include "pch.h"
#include <iostream>
usingnamespace std;
int averaLeaves;
int employNumRetu()
{
int numEmployee;
cout << "Enter the total number of employees in the company: " << endl;
cin >> numEmployee;
while (numEmployee < 1)
{
cout << "Number of employees should be at least 1.";
cout << "Enter the total number of employees again: ";
cin >> numEmployee;
}
for (int i = 1; i <= numEmployee; i++)
{
int total = 0;
int leaves;
cout << "Enter the total number of leaves in the past year for employee " << i << ": ";
cin >> leaves;
while (leaves < 0)
{
cout << "The total number of leaves can not be a negative number." << endl;
cout << "Enter the total number of leaves again: " << endl;
cin >> leaves;
}
total = total + leaves;
return total;
}
return numEmployee;
}
double averaLeavesRetu(int numEmployee, int total)
{
return total / (double)numEmployee;
}
int main()
{
cout << "Average leaves taken by an employee are: " << averaLeaves << endl;
system("pause");
return 0;
}
#include "pch.h"
#include <iostream>
usingnamespace std;
int averaLeaves;
int employNumRetu()
{
int numEmployee;
cout << "Enter the total number of employees in the company: " << endl;
cin >> numEmployee;
while (numEmployee < 1)
{
cout << "Number of employees should be at least 1. \n";
cout << "Enter the total number of employees again: ";
cin >> numEmployee;
}
return numEmployee;
}
double totalLeavesRetu()
{
int total;
int leaves;
for (int i = 1; i <= numEmployee; i++)
{
cout << "Total number of leaves in the past year for employee " << i << ": ";
cin >> leaves;
}
while (leaves < 0)
{
cout << "The total number of leaves can not be a negative number." << endl;
cout << "Enter the total number of leaves again: " << endl;
cin >> leaves;
}
total = total + leaves;
return total;
}
double averaLeavesRetu(int numEmployee, int total)
{
averaLeaves = return total / (double)numEmployee;
return averaLeaves;
}
int main()
{
int numEmployee = numEmployeeRetu();
int total = totalLeavesRetu(numEmployee);
double averaLeaves = averaLeavesRetu(numEmployee, total);
cout << "Average leaves taken by an employee are: " << averaLeaves << endl;
system("pause");
return 0;
}