Hi, I'm working on this program and I wanted to know if I was going in the right direction or not. How am I doing? is there something I should do differently?
Here's a brief description of what I'm working on:
Write a program that calculates the average number of days a Joe's employees have been absent from work because of mining accidents. The program should have the following functions:
A function getEmployees, called by main that asks the user for the number of employees in the company. This value should be returned as an integer. (The function accepts no arguments.)
A function getDays, 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 integer.
A function computeAverage, 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 so far. I know I'm missed things and I need help. Any tips please?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
using namespace std;
int getEmployees();
int getDays();
double computeAverage();
int main()
{
int numOfEmployees = 0;
bool validInput = false;
do
{
cout << "Please enter the number of employees in the company: ";
cin >> numOfEmployees;
validInput = (numOfEmployees >= 1);
if (!validInput)
{
cout << "\nPlease enter a valid number!\n";
}
} while (!validInput);
return numOfEmployees;
}
int getEmployees(int numOfEmployees)
{
cout << "The nuber of employess in the company is: " << numOfEmployees << endl;
return numOfEmployees;
}
int getDays()
{
int daysMissed = 0;
bool validInput = false;
do
{
cout << "Please enter the number of days each employee missed: ";
cin >> daysMissed;
validInput = (daysMissed >= 0);
if (!validInput)
{
cout << "\nPlease no negative numbers!\n";
}
} while (!validInput);
return daysMissed;
}
double computeAverage(int numOfEmployess, int daysMissed)
{
return numOfEmployess * daysMissed;
}
|