Code seems correct still showing compilation error is showing for one case which is absolutely correctly calculated

Please check my code.
It is showing compilation error for input: 1 -8 16 but the answer is coming correct in my editor.

#include
#include
using namespace std;

int main ()
{
int a , b , c;
cin>>a>>b>>c;

int D = b * b - 4 * a * c;
int d = sqrt (D);

if (D > 0)
{
    cout<<"Real and Distinct"<<endl;
    int root1 = (-b + d) / (2 * a);
    int root2 = (-b - d) / (2 * a);
    cout<<root1<<" "<<root2;
}

else if (D == 0)
{
    cout<<"Real and Equal"<<endl;
    int root1 = (-b) / (2 * a);
    int root2 = (-b) / (2 * a);
    cout<<root1<<" "<<root2;
}

else
{
    cout<<"Imaginary"<<endl;
}

return 0;

}

hi @sinchan1509_1a917d7b6cc3cbb9
If Real and Distinct , print the roots in increasing order.(this is mentioned in ques)
so in D > 0
print like this -

cout<<min(root1, root2)<<" "<<max(root1, root2)<<endl;

corrected code -->

Oh my god I just made this silly mistake. Thank you so much for your help. I got it.

1 Like

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.