I am not getting the error

#include
#include<math.h>
using namespace std;
int main() {
int a,b,c;
int root1 , root2;
int d;
int first , second;
d = sqrt((bb)-4a*c) ;

cin>>a>>b>>c;

root1 = (-b + sqrt(d) ) / 2*a ;
root2 = (-b + sqrt(d) ) /2*a ;

/*r1=(-b+sqrt(d))/(2a);
r2=(-b-sqrt(d))/(2*a);*/


if(root1 > root2){
	root1 = first ;
	root2 = second;
}
else
{
	root1 = second;
	root2 = first;
}

if( d > 0 ){
	cout<< "Real and Distinct"<<endl;
	cout<< first <<" "<< second <<endl;
}
if(d = 0){
	cout<<"Real and Equal"<<endl;
	cout<<first<<endl;
}
if(d < 0){
	cout<<"Imaginary"<<endl;
}



return 0;

}

Hello @aayushveer9_9036417178d04a74,

I have listed down all the errors,

  • You need to take input a,b,c first then calculate d
  • d = bb - 4ac you are taking square root twice first while calculating then secondly while calculating root1 and root2
  • You need to print roots in increasing order so your condition is wrong for if ( it should be root1<root2)
  • Also there is no need to calculate root1 and root2 if d<0
  • if d==0 you are printing just one root instead of 2
  • You are printing first and second as ans but your roots are stored in root1 and root2

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

#include #include<math.h> #include using namespace std; int main() { float = r1,r2; float a , b , c; cin>>a>>b>>c; float d; float d1; d = bb-4ac ; d1 = sqrt(d); if(d == 0){ cout<<“Real and Equal”; } else if ( d > 0){ cout<<“Real and Distinct”; } else if ( d < 0){ cout<<“Imaginary”; } cout<<endl; r1 = -b + sqrt(d1)/2a; r2= -b - sqrt(d1)/2*a; if(d > = 0){ if(r1>r2){ cout<<r1<<" “<<r2; }else{ cout<<r2<<”"<<r1; } } return 0; }

Hello @aayushveer9_9036417178d04a74,

I have corrected your code,
Corrected Code

@aayushveer9_9036417178d04a74,

Is it clear now?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.