I am doing work for school, I’m supposed to write a function that accepts the number of employees that work for a company and returns the value to main.
Then I am to write a function called by main that accepts the number of employees that work for the company. I am then supposed to ask the number of days each employee missed in that function and return the total of the days missed.
I’m having a problem on the second part. I am trying to create an array with the number of employees as the max number of elements, but I keep getting an error about the variable I put in between the brackets not being a constant even though it is!
I am a little foggy on arrays and this is meant as a refresher course. If I could just create an array I would use a for loop to go through each element and store the number of days missed in each.
Thanks for any help,
Aaron
#include <iostream>
using namespace std;
int noOfEmployees();
int daysAbsent(int);
int main(){
int employees;
employees = noOfEmployees();
daysAbsent(employees);
system("pause");
return 0;
}
int noOfEmployees(){
int employees;
cout<<"Please enter number of employees/n";
cin>>employees;
return employees;
}
int daysAbsent(int employees){
const int max = employees;
int daysMissed;
int workers [max];
}
int workers[max];is not legal C++, because the size of the array (max) is not a compile-time constant. Even though the variablemaxis declared to be constant after construction, it is constructed at runtime from the argument todaysAbsent, and so the size is not known at compile-time.If you want a variable sized array, try
std::vector: