|
From: Ken B. <ke...@al...> - 2002-12-02 14:21:47
|
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Nathan
Binette
Sent: Saturday, November 30, 2002 3:11 PM
To: dev...@li...
Subject: [Dev-C++] type mismatch
When writing a basic program to perform a calcuation I have set types as
float to receive input (cin). When I enter a character (not a number) when
prompted for input the program terminates. This happens even when using
exception handling
cin.exceptions(cin.failbit);
try{ }
catch (...) { };
I've enabled exception handling via compiler options but this does not
help? Can anyone offer any comments on how to avoid program termination
when type mismatch occurs?
Thanks, Nate
[[Ken]: ]
Why not receive a string, check for validity, and convert to a float?
atof() means ASCII to float
atol() means ASCII to long
atoi() means ASCII to int
#include <stdlib.h>
price = atof (mybuffer);
Checkout http://www.cplusplus.com/doc/tutorial/tut3-2.html.
Ken Bradford
Alpha II Service, Inc.
(614)868-5033
|