第26行的等号处提示:不能将 “int” 类型的值分配到 “POLAR_V”类型的实体
这是什么原因?反复看了好多遍也没找到 “int” 类型
这是什么原因?反复看了好多遍也没找到 “int” 类型
#include<stdio.h> #include<math.h> #define RAD_TO_DEG (180/(4*atan(1))) typedef struct polar_v { double magnitude; double angle; }POLAR_V; typedef struct rect_v { double x; double y; }RECT_V; int main(void) { RECT_V input; POLAR_V result; puts("Enter x,y coordinates;enter q to quit: "); while (scanf("%lf %lf", &input.x, &input.y) == 2) { result = rect_to_polar(input); printf("magnitude =%0.2f, angle =%0.2f\n", result.magnitude, result.angle); } puts("Bye!"); return 0; } POLAR_V rect_to_plar(RECT_V rv) { POLAR_V pv; pv.magnitude = sqrt(rv.x * rv.x + rv.y * rv.y); if (pv.magnitude == 0) { pv.angle = 0.0; } else { pv.angle = RAD_TO_DEG*atan2(rv.y, rv.x); } return pv; }
解决方案
40
1.rect_to_plar需要前置声明
2. result = rect_to_polar(input);应该是 result = rect_to_plar(input);你多了一个o
2. result = rect_to_polar(input);应该是 result = rect_to_plar(input);你多了一个o
#include<stdio.h> #include<math.h> #define RAD_TO_DEG (180/(4*atan(1.0))) typedef struct polar_v { double magnitude; double angle; }POLAR_V; typedef struct rect_v { double x; double y; }RECT_V; POLAR_V rect_to_plar(RECT_V rv); int main(void) { RECT_V input; POLAR_V result; puts("Enter x,y coordinates;enter q to quit: "); while (scanf("%lf %lf", &input.x, &input.y) == 2) { result = rect_to_plar(input); printf("magnitude =%0.2f, angle =%0.2f\n", result.magnitude, result.angle); } puts("Bye!"); return 0; } POLAR_V rect_to_plar(RECT_V rv) { POLAR_V pv; pv.magnitude = sqrt(rv.x * rv.x + rv.y * rv.y); if (pv.magnitude == 0) { pv.angle = 0.0; } else { pv.angle = RAD_TO_DEG*atan2(double(rv.y), rv.x); } return pv; }