I am working on this c++ app for class and have hit a wall.
I have been trying to get the average to display with decimal points for accuracy but have had no luck. Here is the code.
Thanks for any help.
//*************************************************************************
// Include Files
//*************************************************************************
#include <iostream>
#include <iomanip>
using namespace std;
//*************************************************************************
// Function Prototypes follow
//*************************************************************************
int getnumEmpl();
int getdaysOff (int);
double getavg(int, int);
//*************************************************************************
// Variable declarations
//*************************************************************************
int numemployees;
int totalDays;
double avg;
//*************************************************************************
// Main
//*************************************************************************
int main()
{
numemployees = getnumEmpl ();
totalDays = getdaysOff (numemployees);
avg = getavg (numemployees, totalDays);
cout << "Average days off per employee is: " << avg;
return 0;
}
//*************************************************************************
// Function Declarations
//*************************************************************************
int getnumEmpl()
{
int employees;
cout << "How many employees do you have on staff?\n";
cin >> employees;
while (employees <= 1)
{
cout << "You should enter at least 2 employees\n";
cout << "to average.\n";
cout << "How many employees do you have on staff? ";
cin >> employees;
} // end while
return employees;
};
int getdaysOff (int numb)
{
int employeenum, daysOff, totaldaysoff;
employeenum = 0;
totaldaysoff = 0;
while (employeenum < numb) {
employeenum ++;
cout << "How many days off has employee number " << employeenum << " taken? ";
cin >> daysOff;
while (daysOff <= 0)
{
cout << "Please enter a positive number: ";
cin >> daysOff;
} // end while
totaldaysoff += daysOff;
}
return totaldaysoff;
};
double getavg(int numemployees, int totaldayoff)
{
int daysOffAvg;
daysOffAvg = totaldayoff / numemployees;
return daysOffAvg;
}
//*************************************************************************
// Program Output
//*************************************************************************