I recently completed a small console app that accepts input from the user and places it in a floating point array, which was implemented through a for loop. I have not spent much time studying error handling and was wondering if anyone could refer me to a useful error-handling tutorial. I am mostly interested in allowing my program to not only accept erronous input but to seamlessly continue operating. Here is an example of my input function:
bool done = 0;
int counter = 0;
float nums[100], regulator;
cout<<"Input a number (-1 exits): "<<endl;
while(done == 0)
{
cin>>regulator;
if(regulator != -1)
{
nums[counter] = regulator;
counter++;
}
else
{
done = 1;
}
}
I am mostly interested in recovering from characters being used instead of numbers. Also, is there a way for an int to store the ASCII value of a character in case one was input?
Thank you!