i got a function to solve infinite loop in showing error message when user key in character to integer type data....but the function fail to some condition..
This is my function code
getline(cin,inputI);
i=atol(inputI.c_str());
if(i<=-1)
{
cout<<"Please key in only the number that suitable for the grid."<<endl;
t=0;
}
else if(i>size-1)//size is the value that define by user
{
cout<<"Please key in only the number that suitable for the grid."<<endl;
t=0;
}
}
while(!t);
}
when the program run...if i din enter any value...i press enter, the program wills till go without stop and take the previous value of " i" . I need a function that can restrict the input between the range of '0' to 'size ' that define by user and not to infinite loop when key in character to it......
I really can't understand your question, and as English seems to, most likely, be your first language, I'm going to put it down to laziness.
As to that, I'm going to be lazy too, and not answer the question until you word it such that I can actually read it.
How about writing a function that translates what you type into what I can read?
Edit: Upon further reading it actually looks like English isn't your first language, my apologies. But I still can't really understand the question. Please rephrase it.