I am a Uni student and when I try to do this
#include <iostream>
using namespace std;
int main()
{
int L1,L2,L3;
cout << "Lenght of the first Array: ";
cin >> L1;
cout << "Lenght of the second Array: ";
cin >> L2;
L3 = L1 + L2;
int A1[L1], A2[L2], A3[L3];
for (int x = 0; x < L1; x++) {
cout << "Input a Number for space " << x + 1 <<" in array 1 :";
cin >> A1[x];
}
for (int x = 0; x < L2; x++) {
cout << "Input a Number for space " << x + 1 << " in array 2 :";
cin >> A2[x];
}
for (int x = 0; x < L1; x++) {
A3[x] = A1[x];
}
for (int x = L1; x < L3; x++) {
A3[x] = A2[x- L1];
}
cout << "nAll the numbers in both arrays were: ";
for (int x = 0; x < L3; x++) {
cout << A3[x] << " ";
}
}
It gives me an error only in Visual Studio 2022 on line 12 that int A1[**L1**], A2[**L2**], A3[**L3**];
the length i want to input need to be constant values
But when I try the code in other compilers it works fine
in other compilers it give me
Lenght of the first Array: 2
Lenght of the second Array: 2
Input a Number for space 1 in array 1 :1
Input a Number for space 2 in array 1 :2
Input a Number for space 1 in array 2 :3
Input a Number for space 2 in array 2 :4
All the numbers in both arrays were: 1 2 3 4
only in visual studio 2022 is this problem. IDK if the issue is the configuration or installation of VS2022 because I didn’t do it myself
Victor Mejía is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.