### Not able to get the average for output

I am trying to run this program and I can't seem to get the average output on screen. Here is the question along with my code.

Write a program that calculates the average number of days a company s employees
are absent. The program should have the following functions:
* A function called by main that asks the user for the number of employees in the
company. This value should be returned as an int. (The function accepts no
arguments.)
* A function called by main that accepts one argument: the number of employees in
the company. The function should ask the user to enter the number of days each
employee missed during the past year. The total of these days should be returned
as an int.
* A function called by main that takes two arguments: the number of employees in
the company and the total number of days absent for all employees during the
year. The function should return, as a double, the average number of days
absent. (This function does not perform screen output and does not ask the user
for input.)
Input Validation: Do not accept a number less than 1 for the number of employees.
Do not accept a negative number for the days any employee missed.

My code:

// Days Out is the programm that calculates the average number of days a company's
// employees are absent

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980`` ``````#include using namespace std; //Function prototypes int numberEmployees(); int numberDays(int); double averageDays(int, int); int main() { //Declaring variables int employees; int total; double average; //Function call for first function employees = numberEmployees(); //Function call for second function total = numberDays(employees); //Function call for last function prototype average = averageDays(employees, total); //Performing output by main function cout<< "The average number of days a company's employees are absent is: " <>workers; //Input validation if(workers<=1) { cout<<" Do not accept number less than 1. Please, enter again: "; cin>>workers; } return workers; } //Function header for the number of days int numberDays(int w) { int workers = w; int total = 0; int absent; //Creating a loop for every employees' missed days for (int count=0; count>absent; total+=absent; //Input Validation if (absent<0) { cout<<"Please, do not enter negative number! Try again: "; cin>>absent; } } return total; } //Function header for average number of days absent double averageDays (int work, int totl) { int w = work; int t = totl; double aver; aver=(w*365)/t; return aver; }``````
One thing is sure:
(int * 365) / int is (int * int) / int is int / int is int
and integer division drops remainder.

`aver=(w*365.0)/t;` is (int*double)/int is floating point division. Much better here.

Consider this. You have 10 workers and only one of them was one day off. Your "average" will be 3650. Case 2. Only 1 worker, but was absent 365 days. ==> Average of 1?

Just in case some harm would come to the 365, here is another way to enforce floating division:
`aver = static_cast<double>(w) / t;`
Hey thank you soo much. I have tried both, this time the average shows on the output but as soon as it shows on the scree, it crashes; I tried using system ("pause"), still no luck.
what do i do ?
 The function should return, as a double, the average number of days absent.

Based on the above, I think you want average per employee.
Meaning if all employees take 5 days off, the average is 5.
`aver=(t/w);`

also
`if(workers<=1)`
should be
`while(workers<=1)`

This one probably needs to be changed too
`if (absent<0)`
Last edited on
Topic archived. No new replies allowed.