Quote:
Originally Posted by xpi0t0s View Post
There are some odd checks in isvaliddouble() - you might want to think these through with a few example valid doubles. Why is it valid if it's one character long? Why do you need to check if it's one character long more than once? Why is the string valid if you come across a non-digit number? And, critically, what about the decimal separator?

Why are i and start double instead of int?

I'm not a fan of using exception handling instead of "else". However I can see that this could arguably be an exception so if you've been told to use exception handling then leave it in. Otherwise just use else.

Why are (complete entries) "+" and "-" valid? What would the value of these be? Zero?

You call atof() anyway, completely ignoring the return value of isvaliddouble(). Probably if isvaliddouble() returns FALSE you would want to skip the conversion and do something other than return a double - maybe return an error code indicating whether or not the conversion happened and pass in a pointer to a double, which would be used if the validity check passes.

Have you been told to write code to validate the double? atof() implements error checking so if you haven't been explicitly instructed to write code to perform double validation, you could just use the error checking built into atof().

You only check for a sign once but what about scientific notation? +1.2345e+5 is a valid number (and atof converts it correctly to 123450).
The problem states..allow the user to repeatedly enter a string until a string that can be converted into a double is entered.

We are using exception handling by the way.

The code above is just being used to check a DOUBLE value. An example. It asks the user to enter a string(which I just put there for reference to what I actually need the program to do) if they enter anything other than a double precision number it will spit out an error. If I enter 100 then it will just return 100.

Again, I need the user to enter a string. I need to check the string to make sure it can be converted into a double(I think this is where I am confused).

As for your questions as why the + and - are valid. I am absolutely not sure. I am trying to manipulate an example code in the book.The instructor insists it will be much easier to do it this way. I am finding it more difficult. I might just need to go back and rewrite the code without using the example.