|
Hey, let me go ahead and say thanks to anyone who replies to this. My code is a simple console app. that accepts a number as an input, and then uses if/else statements to print out the range of a number.
using namespace std;
int main()
{ double d;
// input a number
cout << "Please enter a number\n";
cin >> d;
// branching staments to derive the range of the number
if(d == 0)
cout << "Zero\n";
else if(d > 0 && d < 10)
cout << "Positive Num Less Than 10\n";
else if(d >= 10)
cout << "Positive Num > Than or Equal To 10\n";
else if(d < 0)
cout << "Negative\n";
else
cout << "Ivalid Input\n";
cout << "Please Try Again\n";
system("PAUSE");
return 0;
}
|
|
The code works, but I've noticed that the final else statement is irrelevant. If I enter anything other than a number, it gets converted to a number. My guess is that c++ turns the characters into asci through inheritance.
My question is, how can I check against faulty entry, and if I can't, can I overwrite the variable class to not allow automatic conversions, or is there a simple exception handling statement i can use?
Anywho, thanx again for any help.
|
|
|
|
|
|
|
// |