#include "stdafx.h"#include "iostream.h"#include "math.h"float dis(int a, int b, int c,int d){return (float)sqrt((a-c)*(a-c)+(b-d)*(b-d));}double dis(double a,double b,double c,double d){return sqrt((a-c)*(a-c)+(b-d)*(b-d));}void main (){cout<<"点(0,0)与点(3,4)的距离为:"<<dis(0,0,3,4)<<endl;cout<<"点(11.2,-25)与点(0.33,11.22)的距离为:"<<dis(11.2,-25,0.33,11.22)<<endl;}
1 回答
慕森卡
TA贡献1806条经验 获得超8个赞
//#include "stdafx.h"
#include "iostream.h"
#include "math.h"
float dis(int a, int b, int c,int d)
{
return (float)sqrt((a-c)*(a-c)+(b-d)*(b-d));
}
double dis(double a,double b,double c,double d)
{
return sqrt((a-c)*(a-c)+(b-d)*(b-d));
}
void main ()
{
cout<<"点(0,0)与点(3,4)的距离为:"<<dis(0,0,3,4)<<endl;
cout<<"点(11.2,-25)与点(0.33,11.22)的距离为:"<<dis(11.2,(double)-25,0.33,11.22)<<endl;
}
这样就能通过.你用dis(11.2,-25,0.33,11.22)是想调用double dis.但是你赋值里面有个-25,可能系统默认为int型,所以系统没找到相应的dis函数.所以你给系统一点提示.强制装换-25为double型
添加回答
举报
0/150
提交
取消