This function is having some errors, even when I use "getline" to get the string input from the user, if the input is more than one word it passes onto cin>>doubVar which terribly messes with the loop (keeps repeating the error message)
In short, why isn't getline working? Why does it mess with the next input value?
//****************************************************
//This function allows the user to input data into the class array
void inputData(Fishing *data, int size)
{
//Dummy variables to temporarily store user-entered values
string strVar;
double doubVar;
for(int i=0;i<size;i++)
{
//Problem is here
cout<<"Enter data for fish #"<<(i+1)<<": "<<endl;
cout<<"Type: ";
getline(cin,strVar);
data[i].setFishType(strVar);
//Input entered into strVar messes with the validation loop of this input (if it is more than 1 word)
cout<<"Length (in inches): ";
cin>>doubVar;
while(doubVar<=0)
{
cout<<"ERROR. Enter a positive non-zero value: ";
cin>>doubVar;
}
data[i].setFishLen(doubVar);
cout<<"Weight (in pounds): ";
cin>>doubVar;
while(doubVar<=0)
{
cout<<"ERROR. Enter a non-zero positive value: ";
cin>>doubVar;
}
data[i].setFishWeight(doubVar);
data[i].getWhatToDo();
system("CLS");
}
}
I tried cin.ignore() and cin.get() to no avail. What is wrong with it?