I am working on a project that is a calculator. I have the project done, but am trying to tweak the code due to one problem. When asked for a number, you put in a letter and it closes the program with erroneous data. I am trying to figure out how to do something similar to as follows.
Input number = program works as intended
Input letter = program recognizes this is not correct and asks to input a number only.
what I am using for the variable now is:
1 2 3
double weight = 0;
cout << "Enter your weight in pounds to one decimal point: ";
cin >> weight;
Using this, it acts as explained above. What can i add to make sure it recognizes its not a number and asks for a number?
Use operator bool instead of good() member function. .good() should be only used to check stream readiness for further inputs, not for checking success of already happened input
in your code: