0

I am getting 3 errors, all for the same reason in two separate section of my code. I have looked around and have yet found a solution. The two seperate codes are:

void getRespRobin(int arrivals[], int n, int bursts[], int resps[], int quanta) { 
// Make a copy of burst times burst_arr[] to store remaining 
// burst times. 
int final_arr[n];  
for (int i = 0 ; i < n ; i++) 
    final_arr[i] =  bursts[i]; 


void findavgTime(int option, int pids[], int arrivals[], int n, int bursts[], int quanta) { 

int resp[n], ta_time[n], avg_resp_time = 0, avg_ta_time = 0; 

The error I am getting for both is "expression must have a constant value. The value of parameter 'n' cannot be used as a constant"

Any recommendations?

  • My recommendation: Start from the smallest piece of code that compiles and proceed from a buildable state to another buildable state. Writing a big bunch of malformed code all at once and trying to fix it after the fact is unproductive. Apropos, where is the closing `}` behind `getRespRobin(...) { ...`? – Andrej Podzimek Oct 24 '21 at 20:28
  • 2
    You are trying to use [variable length arrays](https://stackoverflow.com/questions/1887097/why-arent-variable-length-arrays-part-of-the-c-standard). These are a C language feature, not valid C++. Some compilers accept them as a language extension; MSVC is not one of them. In C++, a dynamically sized array is spelled `std::vector` – Igor Tandetnik Oct 24 '21 at 23:43

1 Answers1

0

int* final_arr = new int[n]; should fix it.