I am building a program that calculates the surface area of a sphere. I also made an additional feature that allows the user to input a positive number only. Before setting my loop, I defined the function for the surface area, but it wouldn't compile because the function is not defined. The code is displayed:
include <stdio.h>
#define PI 3.1415
float sa_sphere(float r);
int main()
{
float r;
do{
printf("Enter a positive radius: ");
scanf("%f", &r);
if (r<0){
printf("Error: number entered is not positive.\n");}
}
while (r<0);{
printf("The surface area is: %.2f\n",sa_sphere(r));}
return 0;
}
I am using Linux Mint to compile it — gcc gg.c
then ./a.out
where gg is my file name.
/tmp/ccRUfp76.o: In function `main':
gg.c:(.text+0x6e): undefined reference to `sa_sphere'
collect2: error: ld returned 1 exit status
I would appreciate any tip to solve it. Please don't display the code in the answer, though.