Help with declaring an array

I am getting an error when i try to declare my array with a value from a different array. The issue is that i could change the value of the variable which would change the size of the array. I tried making the variable a constant value but that didn't seem to work either. Any way to get around this? Perhaps with a try/catch? Thanks.

1
2
3
4
5
6
void factor(int x[])
{
	const int A=x[0],B=x[1],C=x[2];

	int A_Multiples[A];
}
Could try dynamic allocation.
int* A_Multiples = new int[A]
Trying to do this? compiles fine here, maybe if you give us the error we could help... Make sure x[0] has a value...

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

using namespace std;

int main()
{
int x[]{1,2,3};
const int A=x[0],B=x[1],C=x[2];

	int A_Multiples[A];

}
Last edited on
Topic archived. No new replies allowed.