I would like you guys, if you reply, not to tell me the answer directly just like that. Make it tricky so i can understand something or put me do some mindmapping instead.
Here's the code:
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
do
{
if(a = 0)
{
return 0;
}
}while(a < INT_MAX || a > INT_MIN);
}
// if i input "a" as char ( ex: fdsafdsaj21312) program will close or hang.
I would like to know how to handle this, what is a handler or exception and how and what i do with those if they will be involved.
So basically i will be forced to loop the cin in case it returns false.
Will this do it?
int a;
while (!(cin >> a))
{
system("CLS");
PrimaryMenuInterface();
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
This loops the cin routine until it returns true, it clears the screen, clears the cin memory, and ignores numeric limits while the cin activity is against the type of variable i am working with.
Is this ok, and if it's not, what will be the issue?
Newbie here:-S.