//Prompting user for numbers
cout << "Please input two numbers" << endl;
cin >> num1;
cin >> num2;
I am developing a simple C++ calculator for practice. Is there an IsNumeric (from VB) equivalent in C++ where I can prevent user from crashing the program by entering non-numerical inputs? Thank you in advance!
You could try if (cin.bad()) or if (cin.fail())
I'm not sure off the top of my head whether that would be sufficient error checking, but it's worth a shot.
This is the code for very first C++ addition/subtraction calculator. I tried stringstream as suggested but I did not get the desired result as the user gets prompted at the same time for inputting the first and second number. I do not know what went wrong, any help will be appreciated, thank you!
If it's simply that the user is getting prompted to re-enter the first and second number, then you should exclude the user getting prompted from the loop that tests for correct input from the addition/subtraction tree.
I got "Please input the first number" and "Please input the second number" displayed simultaneously but I want the former to appear first followed by the latter. I have no idea how to fix it.
I had tried the small example given by gelatine and it works well. I do not know why mine does not work as expected.