error: no match for operator>>

1.1k views Asked by At

I am a beginner and I have some trouble in building and running a code. This code works perfectly when don't use "cin" and give an initial value to the variables. But it displays an error in line 19 that - error: no match for 'operator>>'
Please explain what is happening and also explain how to fix this error.

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    double a;
    double b;
    double c;
    double p;
    double x1;
    double x2;

    cout<<"Roots of a Quadratic Equation"<<endl;
    cout<<"This application will ask for the coefficient of different terms of a quadratic equation and will return the roots of that equation"<<endl;
    cout<<"Make sure that your equation is in the form ax^2 + bx + c"<<endl;
    cout<<"Enter the coefficient of second order term"<<endl;
    cin>>a>>endl;
    cout<<"Enter the coefficient of first order term"<<endl;
    cin>>b>>endl;
    cout<<"Enter the constant term"<<endl;
    cin>>c>>endl;

    p = b*b-4*a*c;

    if(p<0){
        cout<<"This equation has no true roots"<<endl;
    }
    else{
        x1 = (-b + sqrt(p))/(2*a);
        x2 = (-b - sqrt(p))/(2*a);
        cout<<"Roots are "<<x1<<" and "<<x2<<endl;
    }

    return 0;
}
0

There are 0 answers