#include
using namespace std;
float Sqrt(int n, int dp){
float ans=0,inc=1;
for (int i=0;i<=dp;i++,inc=inc/10){
for (;ans*ans<=n;ans=ans+inc);
ans=ans-inc;
}
return ans;
}
bool SolveQuad (int a, int b, int c, float &x1, float &x2){
int d = bb-4ac;
if (d>=0){
x1 = (-b+Sqrt(d,2))/2a;
x2 = (-b-Sqrt(d,2))/2*a;
}
else return false;
}
int main(){
int a,b,c;
cin>>a>>b>>c;
float x1,x2;
bool isSol = SolveQuad(1,4,4,x1,x2);
if(isSol) cout<<x1<<" "<<x2;else cout<<“No Sol”;
return 0;
}
this works for inputs 1 4 4, 1 0 -4, etc
but doesn’t for many inputs like : 2 3 -5 giving output (roots) as : 2 -12, where actual roots are -3 and 0.5.
i can’t seem to find error in the code. Help. Thanks!