Compile Error求助
查看原帖
Compile Error求助
470334
Chill6楼主2021/8/25 15:26
我试了一下把第四行的变量定义在函数内部也就变成了局部变量就全部通过了,但是定义在了外面就显示“‘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);
}
2021/8/25 15:26
加载中...