I am writing a code where I am asking user to assign value to an array and where user press enter key I want to assign a default value to array elements. Any idea how to proceed with this ?
I have tried using cin.get() method but it is not working. Here is my code :
#include<iostream>
#include<math.h>
#include<cmath>
using namespace std;
int main()
{
int n;
cout << "Enter array size: ";
cin >> n;
double y[n];
string input;
for(int i=0; i<n; ++i)
{
cout << "Enter Initial Velocity ( Default Value 0 ) : " ;
y[i] = cin.get();
if (input=="")
{
y[i]=0.0;
}
else
{
y[i]=stod(input);
}
}
}