为什么这样写提交会编译失败,求大佬解释?

P5735 【深基7.例1】距离函数

Kx_Triumphs @ 2023-08-14 10:40:17

#include<bits/stdc++.h>
using namespace std;
const int B=0;
double x1,y1,x2,y2,x3,y3,ans;
void dis(double x_1,double y_1,double x_2,double y_2){
    double t=pow(abs(x_2-x_1),2)+pow(abs(y_2-y_1),2);
    ans=ans+sqrt(t);
} 
int main(){
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    dis(x1,y1,x2,y2);
    dis(x1,y1,x3,y3);
    dis(x2,y2,x3,y3);
    printf("%.2lf",ans);

    return 0;
}
/*
0 0
0 3
4 0
*/

by xuzihao123 @ 2023-08-14 10:41:29

@kai_xuan_m

不会啊


by xuzihao123 @ 2023-08-14 10:41:41

编译器的问题吧


by gongziwen @ 2023-08-14 10:42:23

@kai_xuan_m y1


by ssSSSss_sunhaojia @ 2023-08-14 10:52:28

你使用了万能头文件,y1会被当成一个函数名,所以你应该把y1换个变量名。


by Kx_Triumphs @ 2023-08-14 10:56:43

@ssSSSss_sunhaojia 知道了,谢谢


|