Question: Write a C++ function named isvalidReal() that checks for a valid double-precision number. This kind of number can have an optional + or - sign,

Write a C++ function named isvalidReal() that checks for a valid double-precision number. This kind of number can have an optional + or - sign, at most one decimal point (which can be the first character), and at least one digit between 0 and 9. The function should return a Boolean value of true if the entered number is a real number; otherwise, it should return a Boolean value of false. Then modify the isvalidReal() function written to remove all leading and trailing blank spaces from its string argument before determining whether the string corresponds to a valid real number.

** This is what I have so far for this program. I feel like I am close, just need some help tweaking and debugging as it is not recognizing the real number. The feedback I got was "You have to check for a decimal point. Just One." I have to be overlooking something simple: **

Write a C++ function named isvalidReal() that checks for a valid double-precision

11 | E#include 12 13 14 15 bool isvalidReal(string); 16 17 int main() 18 19 20 21 #include using namespace std; string str; double number; cout = 1) valid = false; i = start ; while (valid && double(str.length())) if (lisdigit(str.at(1))) valid false; if (str.at (i) == '-') valid = true; 56 57 58 59 60 61 62 return valid

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!