How do i fix this error: undefined reference to `distance(float, float, float, float)'

How do i fix this error: undefined reference to `distance(float, float, float, float)'

所以我不太确定在这里做什么,我已经多次回顾我的代码,一切似乎都是正确的,但我一直收到错误代码

Stubblefield9.cpp:74: 未定义对`distance(float, float, float, float)'的引用 collect2.exe:错误:ld 返回了 1 个退出状态

如果有人能帮助我,这是我的代码。

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
const float pi=3.14;
int choice;
char again;

   do
   {
       cout << "  IHCC Computer Science Registration Menu\n";
       cout << "  ======================================\n";
       cout << "  1.  The Volume of a Cone\n";
       cout << "  2.  The Volume of a Sphere\n";
       cout << "  3.  The Area of an Octagon\n";
       cout << "  4.  The Destance between two Points\n";
       cout << "  ======================================\n";
       cout << "  Enter your selection: ";

cin >> choice;

switch (choice)
{
case 1:
    float coneRadius,coneHeight,coneVolume;
    cout<<"Enter the Radius of the cone:";
    cin>>coneRadius;
    cout<<"\nEnther the Height of the Cone: ";
    cin>>coneHeight;
    coneVolume=pi*coneRadius*coneRadius*coneHeight/3;
    cout<<"\nThe Volume of a Cone with Radius ("<< coneRadius << ") and  Height (" << coneHeight << setprecision(2) << fixed << ") is " << coneVolume;
break;
case 2:
float sphereRadius,sphereVolume;
   cout << "Please insert the Radius: ";
   cin >>sphereRadius;
   sphereVolume = (4/3)*(pi)*(sphereRadius*sphereRadius*sphereRadius);
   cout<<"Volume with radius "<< setprecision(1) << fixed << sphereRadius << setprecision(2) << fixed << " is "<<sphereVolume;
break;
case 3:
float octagonSide, octagonArea;
cout << "Input side length: ";
 cin >> octagonSide;
octagonArea =(2 * (1 + sqrt(2)) * octagonSide * octagonSide); 
cout << "\nThe area of the octagon with side length (" << octagonSide << setprecision(2) << fixed << ") is "<< octagonArea;

break;
case 4:
float x, y, a, b, answer;

  float distance(float x, float y, float a, float b);
       cout << "Enter the points for the coordinates";
       cout << endl;
       cout << "Point x for first coordinates: ";
       cin >> x;
       cout << endl;
       cout << endl;
       cout << "Point y for first coordinate: ";
       cin >> y;
       cout << endl;
       cout << endl;
          cout << "Point x for the second coordinate: ";
       cin >> a;
       cout << endl;
       cout << endl;
       cout << "Point y for the second coordinate: ";
       cin >> b;
       cout << endl;
       cout << endl;
       answer = distance(x, y, a, b);
       cout << "The answer is " << answer;
break;
default:
cout << "Not a Valid Choice. \n";
cout << "Choose again.\n";
cin >> choice;
break ;
}
     cout << "\n\n Would you like to do it again(y or n)";
     cin >> again;
  }  while( again == 'y' || again == 'Y' );
return 0;
}

您收到该错误是因为您尝试调用代码中由

声明的函数 distance()

float distance(float x, float y, float a, float b);

但未定义。