私は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