I am new to C++ and something wrong is happening,
Basically, I have declared a variable called number
which is of type int
.
If I input a string such as a
or x...
then number becomes 0
. I don't want number to become 0
and instead want it to be error handled.
How do I prevent this is C++? This is my source code...
#include <iostream>
using namespace std;
int number;
int main() {
cout << "Please input a number: ";
cin >> number;
cout << number << endl;
return 0;
}