c++编程学习问题

#include <iostream>
#include<cmath>
struct polar
{
double distance;
double angle;
};
struct rect
{
double x;
double y;
};
polar rect_to_polar(rect xypos);
void show_polar(polar dapos);
using namespace std;
int main()
{
rect rplace;
polar pplace;
cout << "Enter the x and y values: ";
while (cin >> rplace.x >> rplace.y)
{
pplace = rect_to_polar(rplace);
show_polar(pplace);
cout << "Next two numbers(q to quit): ";
}
cout << "Bye !\n";
return 0;
}

polar rect_to_polar(rect xypos)
{
using namespace std;
polar answer;
answer.distance = sqrt(xypos.x * xypos + xypos.y * xypos.y);
answer.angle = atan2(xypos.y, xypos.x);
return answer;
}
void show_polar(polar dapos)
{
using namespace std;
const double Rad_to_deg = 57.29577951;
cout << "distance = " << dapos.distance;
cout << ", angle = " << dapos.angle*Rad_to_deg;
cout << " degree\n";
}
编译后的问题是
错误 1 error C2677: 二进制“*”: 没有找到接受“rect”类型的全局运算符(或没有可接受的转换)
不知道错哪了,求教

看这行代码,你应该是想要算距离,少了.x

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答