Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7159825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:17:44+00:00 2026-05-28T13:17:44+00:00

I am doing work for school, I’m supposed to write a function that accepts

  • 0

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];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:17:45+00:00Added an answer on May 28, 2026 at 1:17 pm

    int workers[max]; is not legal C++, because the size of the array (max) is not a compile-time constant. Even though the variable max is declared to be constant after construction, it is constructed at runtime from the argument to daysAbsent, and so the size is not known at compile-time.

    If you want a variable sized array, try std::vector:

    #include <vector>
    int daysAbsent(int employees) {
        const int max = employees;
        int daysMissed;
        std::vector<int> workers(max);
        cin>>daysMissed;
        //Use workers somewhere in here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing some work on a web site that has a secure area
I am doing some work on an asp website that uses Access as its
I'm doing maintenance work on a Rails site that's deployed using Phusion Passenger .
I am doing a bit of preliminary investigation for my school (I work for
I am doing work for a client that has a server on his domain.
I am doing work involving a lot of DOM manipulation. I wrote a function
After doing some work with Ruby, Rails, and RSpec last summer and I learned
I am doing some work to track down a perceived bug in a git
I'm doing some work with Ukkonen's algorithm for building suffix trees, but I'm not
I'm doing some work with registry hives, and I need to know if the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.