434,694 Members | 1,294 Online
Need help? Post your question and get tips & solutions from a community of 434,694 IT Pros & Developers. It's quick & easy.

Windows program gives me -1.#IND as a number result. What the heck is that?

 P: 6 Hello all! First I would like to thank all of those who helped me regarding my first assignment...I'm much better with my semicolons now. A couple assignments later...I'm having problems again. I'm supposed to create a very simple C++ program calculating the answers to a quadratic equation in form a(x^2) + b(x) + c. I thought i had no problems typing the code, but when I test 1, 2 and 3 for a, b, and c variables respectively, I get "-1.#IND" as my answer when it should be -1. What's going on?? Expand|Select|Wrap|Line Numbers #include  #include    using namespace std;    int main() {   double a = 0;   double b = 0;   double c = 0;     cout << "The current value of a is "<> a >> b >> c;      cout << "Your expression is "<
3 Replies

 Expert 100+ P: 1,510 so long as you are dealing with real roots you only had one problem and that was you set the result of x1 to 1, e.g. Expand|Select|Wrap|Line Numbers  double x1 = 1;   double x2 = ((-1*b) - sqrt(pow(b,2.0) - 4*a*c))/(2*a);   I have fixed that Expand|Select|Wrap|Line Numbers   #include  #include    using namespace std;    int main() {   double a = 0;   double b = 0;   double c = 0;     cout << "The current value of a is "<> a >> b >> c;      cout << "Your expression is "<

 P: 6 Thank you so much for your help!! I didn't realize that I maybe shouldn't have used 1, 2, and 3. Jan 29 '07 #3

 Expert Mod 5K+ P: 8,916 It is easy to test if the result will be complex, compare pow(b,2.0) AND 4*a*c if pow(b,2.0) > 4*a*c    2 real roots if pow(b,2.0) == 4*a*c    1 real root if pow(b,2.0) < 4*a*c    2 complex roots Also before performing the calculation it would be good to test that a != 0 otherwise you will get a divide by 0 error. In most programming the code to handle the success case (when the program operates successfully as specified) is normally <60% of the code, sometimes <40%, these rest is all error handling conditions. However it is this error handling that most often gets leftout by inexperienced programmers. This is also why programmes are twice as complex to write as they initially appear, because a lot of people initially forget to think about the error handling cases. Jan 30 '07 #4