Mail Archives: djgpp/1998/05/03/11:02:03
On Thu, 30 Apr 1998 16:34:44 +1000, Oon Lin <Oon DOT Lin AT jcu DOT edu DOT au>
wrote:
>I had been surfing around Delorie's lib C online reference for a
>function that can test whether an input is in float or int.
>
>For example , let's say I have a float variable named foo.
>
>When I get the input using
>
>cin << foo ;
>
>I'd like to test is if the input was convertable to an int without loss
>of precision. For example , if the input given was 6.0000 , then
>converting it to an int would give 6. But if the input was 6.1234 , then
>conversion should not take place.
>
Why couldn't you just do something like
void fori() {
float input;
int check;
cin >> input; // argh, i always forget which < or > to use here ;)
int check = (int)input;
if ((float) check < input)
cout << "You passed me a floating point value" << endl;
else if ((float) check == input)
cout << "You passed me an integer value" << endl;
} // end void fori
Thanks,
random
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Do Not Send Me Unsolicited Email!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- Raw text -