K
kronahs
Guest
I was trying to find the roots of a quadratic equation in C++.Their two problems :its shows me ' Expected ";" before string constant '.The other problem is that the variables "tot2 " and "tot3 "are showing "nan" in the output when I skipped the debugging . Thanks in advance!
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
float a,b,c ;
float disc,tot1,tot2,tot3;
cout <<"Enter number a: ";
cin >> a;
cout <<"Enter number b: ";
cin >> b;
cout <<"Enter number c: ";
cin >> c;
disc = (b*b)-4*a*c;
tot1 = ((sqrt(disc)));
tot2 = -b + tot1/(2*a);
tot3 = -b - tot1/(2*a);
cout <<"Roots are : , ";
cout << tot2 "\t" << tot3 :"\t" ;
return 0;
}
Continue reading...
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
float a,b,c ;
float disc,tot1,tot2,tot3;
cout <<"Enter number a: ";
cin >> a;
cout <<"Enter number b: ";
cin >> b;
cout <<"Enter number c: ";
cin >> c;
disc = (b*b)-4*a*c;
tot1 = ((sqrt(disc)));
tot2 = -b + tot1/(2*a);
tot3 = -b - tot1/(2*a);
cout <<"Roots are : , ";
cout << tot2 "\t" << tot3 :"\t" ;
return 0;
}
Continue reading...