Chill6 @ 2021-08-25 15:26:07
我试了一下把第四行的变量定义在函数内部也就变成了局部变量就全部通过了,但是定义在了外面就显示“‘double y1’被重新声明为不同意义的符号”,想问问是什么原因造成的,谢谢!
#include<cstdio>
#include<cmath>
using namespace std;
double x1, x2, x3, y1, y2, y3, ans;
double sq(double x){
return x * x;
}
double dist(double a1, double b1,double a2, double b2){
return sqrt(sq(a1 - a2) + sq(b1 - b2) );
}
int main() {
scanf("%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
ans = dist(x1, y1, x2, y2);
ans += dist(x1, y1, x3, y3);
ans += dist(x2, y2, x3, y3);
printf("%.2f", ans);
}
by 159号程序员 @ 2021-08-25 15:28:00
@Chill6 y1是系统关键字,不能作为变量名的
by Textbook_blasphemy @ 2021-08-25 15:29:28
@Chill6 y1,x1与c++某个头文件定义的重名但你好像没用万能头
by CGDGAD @ 2021-08-25 15:38:24
cmath 里有 x1 y1
by xiaoxixi1234567 @ 2021-08-25 16:12:12
CE=compile easily=轻松的编译成功
[doge]
by Chill6 @ 2021-08-27 16:57:26
@159号程序员 好的,谢谢解答!现在知道了!
by Chill6 @ 2021-08-27 16:58:24
@陶(戴)佳伟 谢谢解答!现在知道问题出在哪里了!
by Chill6 @ 2021-08-27 17:00:48
@NSObject 谢谢!我现在明白了,特别感谢解答!