我試圖調用dist()
方法,但是我總是收到一個錯誤,說dist()
必須返回一個值。計算距離:方法「必須返回一個值」?
// creating array of cities
double x[] = {21.0,12.0,15.0,3.0,7.0,30.0};
double y[] = {17.0,10.0,4.0,2.0,3.0,1.0};
// distance function - C = sqrt of A squared + B squared
double dist(int c1, int c2) {
z = sqrt ((x[c1] - x[c2] * x[c1] - x[c2]) + (y[c1] - y[c2] * y[c1] - y[c2]));
cout << "The result is " << z;
}
void main()
{
int a[] = {1, 2, 3, 4, 5, 6};
execute(a, 0, sizeof(a)/sizeof(int));
int x;
printf("Type in a number \n");
scanf("%d", &x);
int y;
printf("Type in a number \n");
scanf("%d", &y);
dist (x,y);
}
閱讀有關操作順序。 'x [c1] - x [c2] * x [c1] - x [c2]'不會做你想要的。 – aschepler 2012-03-13 17:58:37