我是初学者,在构建和运行代码时遇到了一些麻烦。当不使用“cin”并为变量赋予初始值时,此代码可以正常工作。但它在第19行显示错误 -
错误:不匹配'运营商>>'
请解释发生了什么,并解释如何解决此错误。
#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;
}