We were given an assignment yesterday to have it submitted today,i did the solution to it only to find it working abnormally. The question was to find the root of a simple quadratic equation(the quoted "real" is just to scare the heck outta us"
here's my code which runs fine,no error but the results looks like 1.#ID,kinda weird
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<iostream>
#include<math.h>
usingnamespace std;
int main(){
signedint a,b,c,e;
float d,f,g;
cout<<"Enter the value of a: ";
cin>>a;
cout<<"B here: ";cin>>b;
cout<<"C here: ";cin>>c;
d=sqrt((b*b)-(4*a*c));
e=(-1*b);
f=(e+d)/(2*a);
g=(e-d)/(2*a);
cout<<"The root of the quadratic equation is "<<f
<<" and "<<g<<endl;
system("pause");
return 0;
}
Enter the value of a: 2
B here: 5
C here: -2
The root of the quadratic equation is 0.350781 and -2.85078
Press any key to continue . . .
The only thing you might want to do is check to make sure the roots are real, or you'll get NaNs in your output.
Oh, and #include <cstdlib> because you're using system("pause").
(or, preferably, use something other than system() )
@longdoublemain...thnx for testing,I'll include the header file,see if it works
@naraku thnx i used Any! Starting with any random variable entered thru' your keyboard.But when i tried something like say,a=1,b=5,c=6(just for example),what i get is -1.#1D and 1.#1N which is the weird part for me. For emphasis sakes,i use DevC++4.9.9