So for a short introduction, im learning c++ and my question is kinda basic, i have been given a simple c++ question to check wether an integer is a positive, negative or zero but there is a fourth condition and its an error or unknown value just in case symbols or characters have been used in the input
#include <iostream>
using namespace std;
int main()
{
int num;
cout << "Enter an integer: " << '\n';
cin >> num;
if (num > 0)
cout << "The number is positive" << '\n';
else if (num < 0)
cout << "The number is negative" << '\n';
else if (num == 0)
cout << "Zero" << '\n';
else
cout << "Error" << '\n';
return 0;
}
As you can see above, everything works fine but until one thing that while when i used a character or any other symbol it reads it as a zero
i know its kinda silly question but i spent hours and nothing worked out, i tried removing the num==0 statement and it worked fine but i also wanted that 0 statement too, any help provided would be appreciated