codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Newbie question regarding variable type  scalex27 at 17:26 on Saturday, September 15, 2007
 

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.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Job @ EarlySail
•  Job @ EarlySail (perl)
•  Security - Code verify
•  IPC problem
•  Re: import contacts of msn/yahoo
•  Cookies and Threads C++
•  right justify a background in a table?
•  Help with Loop (C++/MFC)
•  Help with Loop (C++/MFC)


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007