Trying to find the average number of days absent employees and i keep getting a integer division by zero error. not sure how to correct it but any help would be appreciated!
#include <iostream>
#include <iomanip>
usingnamespace std;
int employee();
int numberdays (int);
double avgnum (int, int);
int employeenumbers, employeenums, numdays;
int main()
{
employee();
numberdays (employeenums);
avgnum (employeenums, numdays);
system("pause");
return 0;
}
int employee ()
{
int employeenums;
cout<<"Enter the number of employees in the company: "<<endl;
cin>>employeenums;
while (employeenums<1)
{ cout<<"Enter a number greater than 1: "<<endl;
cin>> employeenums;
}
cout<<"The number of employees in the company is "<<setprecision(2)<<fixed<<employeenums<<endl;
return employeenums;
}
int numberdays (int employeenums)
{
int numdays;
cout<< "How many days did each employee miss during the past year?"<<endl;
cin>>numdays;
while (numdays<0)
{ cout<<"Enter a non-negative number of days: "<<endl;
cin>> numdays;
}
cout<<"The number of days missed is: "<<numdays<<endl;
return numdays;
}
double avgnum (int employeenums, int numdays)
{
double avg;
avg= numdays/employeenums;
cout<<"the avg is "<<setprecision(2)<<fixed<<avg<<endl;
return avg;
}
// In your program you dont use employeenumbers so delete it
// also your functions return but you dont use the values returned ,also if you have a global variables and if you insect using those global variables well you dont need to return anything .Turn the function's prototypes to void or delete the global variables
// int numberdays (int employeenums) dont use the parameter employeenums so delete it
// finnaly your program crashs because you using a local variables that share the same name as your global ones
in fact ,your global variables are not been assinged at all so they will be set to 0 0 or some random values
# include <iostream>
# include <iomanip>
usingnamespace std;
int employee(void);
int numberdays(void);
double avgnum(int, int);
int main()
{
int employeenums,numdays;
employeenums = employee();
numdays = numberdays();
avgnum(employeenums,numdays);
return 0;
}
int employee(void)
{
int employeenums;
cout << "Enter the number of employees in the company:" << endl;
cin >> employeenums;
while(employeenums<1)
{
cout << "Enter a number greater than 1: "<<endl;
cin >> employeenums;
}
cout << "The number of employees in the company is " << setprecision(2) << fixed
<< employeenums << endl;
return employeenums;
}
int numberdays(void)
{
int numdays;
cout << "How many days did each employee miss during the past year?" << endl;
cin >> numdays;
while(numdays<0)
{
cout << "Enter a non-negative number of days: " << endl;
cin >> numdays;
}
cout << "The number of days missed is: " << numdays << endl;
return numdays;
}
void avgnum (int employeenums, int numdays)
{
double avg;
avg = (double)numdays/employeenums;
cout << "the avg is " << setprecision(2) << fixed << avg << endl;
}