i have following simpled algorithm for calculation roots of quadratic equation
#include <iostream>
#include <math.h>
using namespace std;
int main(){
float x,x1;
x=0;x1=0;
int a=1;
int b;
int c;
cout<<"enter the second term:"<<endl;
cin>>b;
cout<<"enter the third term:";
cin>>c;
float d=b^2-4*a*c;
if (d<0){
cout<<"the equation has not real solution :"<<endl;
}
else if (d==0) { x=(-b/2); x1=x;}
else
{
x=(-b+sqrt(d))/2;x1=(-b-sqrt(d))/2;
}
cout<<"roots are :"<<x<< " "<<x1<< " "<<endl;
return 0;
}
but it gives me warning
arning C4244: '=' : conversion from 'int' to 'float', possible loss of data
and when i enter -6 and 9 it gives that roots are 6 and zero which of course is not true please help me
^is the bitwise xor operator, not the power, as you probably think. To raise a number to an arbitrary power, usestd::pow(from the standard headercmath). For powers of two, you can just usex * x.