error in returning roots

Hi guys I'm having a problem with my program it's supposed to return roots but when I enter certain values the roots return like this

-1.#IND

i don't know what's wrong since it compiled properly
Thanks for your time :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <vector>
#include <iostream>
#include <cmath>
#include <complex>

using namespace std;
vector <double> values (4);
class parabola
{
 	  double A,B,C,x;
 	  public:
      parabola ();
      parabola (vector<double>values);
      void solve_y()
      {
        	cout << A*(x*x)+B*x+C;
      }
	  double solve_y(vector<double>values)
	  {
	   	  return (A*(x*x)+B*x+C);
	  }
	  double discriminant()
	  { return (pow(B,2)-(4*A*C));}
	  void count_roots();
	  double roots1(vector<double>values);
   	  double roots2(vector<double>values);
}test,trial(values);

parabola::parabola ()
{
   A=1;
   B=1;
   C=1;
   x=1;
}

parabola::parabola (vector<double>values)
{
   A=values[0];
   B=values[1];
   C=values[2];
   x=values[3];
}

int main ()
{
 		
 	cout << "This program is meant to solve for the value of y in the formula: " << endl;
    parabola test;
    cout << endl << "The result of y when all values are 1 is: " ;
    test.solve_y(); 
	cout << endl;
 	cout << "y = Ax^2 + Bx + C (parabola)" << endl;
 	cout << "Enter the value of A:" << endl;
 	cin >> values[0];
 	cout << "Enter the value of B:"<< endl;
 	cin >> values[1];
 	cout << "Enter the value of C:" << endl;
 	cin >> values[2];
 	cout << "Enter the value of x:" << endl;
 	cin >> values[3];
 	parabola trial(values);
    cout << "The result of y is: " << trial.solve_y(values) << endl;
    trial.count_roots();
 	cout << endl;
    system ("pause");
 	return 0;
}

double parabola::roots1(vector<double>values)
{
  return ((-B+sqrt(trial.discriminant()))/(2*A));
}
double parabola::roots2(vector<double>values)
{
	   	   return ((-B+sqrt(trial.discriminant()))/(2*A));
}

void parabola::count_roots()
{
   	   	if (discriminant() > 0)
   	   	{
	      cout << "The number of real roots are: 2" << endl;
	      cout << "The roots are: " << trial.roots1(values)<< "and " << trial.roots2(values) << endl;
	    }
	    else if (discriminant()==0)
	    {
 	      cout << "The number of real roots are: 1" << endl;
 	      cout << "The roots are: " << trial.roots1(values);
	    }
	    else
	    {
          cout << "The number of real roots are: zero" << endl;
	    }        
}	  
	  
      

Last edited on
Does it happen whenever A is zero? Dividing by zero is bad, and that's an output typical of dividing by zero.
Well I haven't tried making A zero. The values that I used where

A = 5
B = 25
C = 6
x = 3

and it returned -1.#ind the answer however was supposed to be (-25+(sqrt of 505))/10
Last edited on
One thing I notice not related to your problem is that the formulas for roots1 and roots2 are the same.
-1.#ind may be returned if you try to take the square root of a negative number. Of course 505 isn't negative so there might be an error in your formula.
Oh I see thank you :) I'll fix it right away
Topic archived. No new replies allowed.