### Integer division by zero

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!

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162`` ``````#include #include using namespace 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: "<>employeenums; while (employeenums<1) { cout<<"Enter a number greater than 1: "<> employeenums; } cout<<"The number of employees in the company is "<>numdays; while (numdays<0) { cout<<"Enter a non-negative number of days: "<> numdays; } cout<<"The number of days missed is: "<
// 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

I suggest this new version

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859`` ``````# include # include using namespace 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: "<> 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; }``````

hope thats helps
Last edited on
Topic archived. No new replies allowed.