Im having some isues when I try to run my C++ program. What does it do is ask the user for the size of the array and what type of array is, double or int, then depending on the user choise, it declares the array, then it calls a function that fills the array with user values
#include <iostream>
using namespace std;
template<class T>
void fill(T *arr,int size){
for(int i = 0; i < size; i ++){
cout<<"Insert value " << i << " :" ;
cin >> arr[i];
}
}
int main(){
int option,size;
cout << "Size? ";
cin >> size;
cout << "1 = double" << endl
<< "2 = int" << endl;
cin >> option;
if(option == 1){
double arr[size];
}
else if(option == 2){
int arr[size];
}
fill(arr,size);
return 0;
}
But when I try to run it, I got this error
test.cpp: In function ‘int main()’: test.cpp:24:7: error: ‘arr’ was not declared in this scope fill(arr,size); ^