I am writing a code that takes a number as the array length and asks the user to input values into it. The problem with my code is that when I print out the values of the array it would give out random values that were never part of the array in the first place. I looked online for all of this and the code just seems right to me but for some reason it is not printing out properly.
#include <iostream>
using namespace std;
int main(){
int x, input;
cout<<"Enter the number of values: "<< endl;
cin >> x;
int arr[x];
cout<<"Enter the values: "<< endl;
for(int i = 0; i < x; i++){
cin>>input;
input = arr[i];
}
cout<<" "<< endl;
for(int i = 0; i < x; i++){
cout<< arr[i]<<endl;
}
return 0;
}
input = arr[i];butarr[i] = input;int arr[x];is not standard C++. Just usestd::vectorfor variable length array.