Hello,
I am currently independently studying C++ before I reach my classes in the Fall. I have been tinkering with programming a special calculator. Unfortunately, if the user inputs a letter, it causes the program to loop endlessly in some cases. I have nulified it some places of my program, but not in others. I have done so by using an if funcition found below.
-------------------------------------------------------------------
if(!(x) || !(y))
{
printf("Error: Invalid Character");
return 0;
}
else...
-------------------------------------------------------------------
X and Y are retireived from the user using std::cin >> X.
Anyways, in other areas, this is not a problem.
A few comments on my program.
1) It is an extrememly beginner program, mostly just if functions and switches.
2) I only have a main().
3) The whole thing is enclosed in a while(iLoop == 1) loop. I did this becuase at the end of the program the user is prompted to continue back to the beginning or to exit, which will then reset iLoop.
4) I am using Microsoft Visual C++ 2010 Express.
5) Question within a question, is this a buffer overflow?
In short, my question would be: How do I get my program to ignore ASCII characters all together, as there is no need for them in this program?
That if statement is ill-formed. But to answer your question, when you try to read a character into a integer, it obviously fails, which sets cin into an error state where you can no longer read input. To avoid this, you could read into a string and then convert to a number, or read character by character and assemble the input somehow.
Thank you for the help. I am trying to shy away from using other's work (I know reinventing the wheel is redundant) so that I can learn myself. I have spent 15 hours on this one issue already and finally decided to post after researching. Again, thank you.