嗨,大家好,
当我尝试执行和编译我的代码时
#include <stdio.h>
#include <math.h>
#define PI 3.14159
void MainMenu();
double MenuToChoose(double R,double r,double volume,double area,int choice);
double FindTheVolumeAndSurfaceArea(double R,double r);
double Compute(double R,double r,double volume,double density,int choice1,double mass,double L1,double S1,double C1,double B1,double N1,double I1,double A1);
int main(){
int choice;
double R,r,volume,area;
do{
MainMenu();
MenuToChoose(R,r,area,volume,choice);
}
while (choice != 3);
}
void MainMenu(){
int choice;
double R,r;
double area,volume;
printf("\n-------------------------------------------");
printf("\n1- Volume and Surface area of the sphare");
printf("\n2- Mass of the sphare");
printf("\n3- Exit");
printf("\n\n Please Enter your Choice: ");
scanf("%d",&choice);
printf("\nYour choice is: %d",choice);
if(choice == 1){
printf("\nYour have chosen to find Volume and Surface area: ");
printf("\nEnter Radii of the sphere: ");
scanf("%lf %lf",&R,&r);
FindTheVolumeAndSurfaceArea(R,r);
}
if(choice == 2){
MenuToChoose(R,r,area,volume,choice);
}
if(choice == 3){
printf("Your choice (3) to Exit.");
printf("\nThanks for using my program !");
return ;
}
double MenuToChoose(double R,double r,double area,double volume,int choice){
char choice1,L,l,S,s,C,c,B,b,N,n,I,i,A,a;
double mass,L1,S1,C1,B1,N1,I1,A1,density;
printf("\nYour have chosen to find Mass of object: ");
printf("\nEnter Radii of the sphere: ");
scanf("%lf %lf",&R,&r);
printf("\nSolids Density (g/cm3)");
printf("\n--------------------------------");
printf("\nL Lead 11.37");
printf("\nS Silver 10.57");
printf("\nC Copper 8.92");
printf("\nB Brass 8.90");
printf("\nN Nickel 8.57");
printf("\nI Iron 7.90");
printf("\nA Aluminium 2.67");
density = L1 = 11.37;
density = S1 = 10.57;
density = C1 = 8.92;
density = B1 = 8.90;
density = N1 = 8.57;
density = I1 = 7.90;
density = A1 = 2.67;
printf("\n Enter choice: ");
scanf(" %c",&choice1);
Compute(R, r, volume, density,choice1, mass, L1, S1, C1, B1, N1, I1, A1);
return density;
return choice1;
return L1;
return S1;
return C1;
return B1;
return N1;
return I1;
return A1;
}
double FindTheVolumeAndSurfaceArea(double R,double r){
double area,volume;
area = 3 * PI * pow(r,2) + PI * (pow(R,2));
volume = ((4/3.0) * PI * (pow(r,3) - pow(R,3) ))/2;
printf("\n\nVolume = %.2lf Area = %.2lf",volume,area);
MainMenu();
}
double Compute(double R,double r,double volume,double density,int choice1,double mass,double L1,double S1,double C1,double B1,double N1,double I1,double A1){
printf("\nEnter Radii of the sphere: ");
scanf("%lf %lf",&R,&r);
/********************************************************/
if(choice1 == 'L' || choice1 == 'l'){
mass = volume * L1;
printf("\nSemi Sphare mass = %.2lf\n\n",mass);}
else if(choice1 == 'S' || choice1 == 's'){
mass = volume * S1;
printf("\nSemi Sphare mass = %.2lf\n\n",mass);}
else if(choice1 == 'C' || choice1 == 'c'){
mass = volume * C1;
printf("\nSemi Sphare mass = %.2lf\n\n",mass);}
else if(choice1 == 'B' || choice1 == 'b'){
mass = volume * B1;
printf("\nSemi Sphare mass = %.2lf\n\n",mass);}
if(choice1 == 'N' || choice1 == 'n'){
mass = volume * N1;
printf("\nSemi Sphare mass = %.2lf\n\n",mass);}
else if(choice1 == 'I' || choice1 == 'i'){
volume = ((4/3.0) * PI * (pow(r,3) - pow(R,3) ))/2;
mass = volume * I1;
printf("\nSemi Sphare mass = %.2lf\n\n",mass);}
else if(choice1 == 'A' || choice1 == 'a'){
mass = volume * A1;
printf("\nSemi Sphare mass = %.2lf\n\n",mass);}
/*******************************************************/
}
}
//void Check(R,r){
// int temp;
// if (R > r)
// {
// temp = R;
// R = r;
// r = temp;
// }
//}
//
我收到以下错误:
main.c: In function ‘MainMenu’:
main.c:26:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&choice);
^
main.c:31:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lf %lf",&R,&r);
^
/tmp/ccP8hsTP.o: In function `MainMenu':
main.c:(.text+0x105): undefined reference to `FindTheVolumeAndSurfaceArea'
main.c:(.text+0x132): undefined reference to `MenuToChoose'
/tmp/ccP8hsTP.o: In function `main':
main.c:(.text.startup+0x22): undefined reference to `MenuToChoose'
collect2: error: ld returned 1 exit status
到底是怎么回事?!我试图解决很多次,但我不能
谢谢,
III
最佳答案
您在}
的末尾缺少右花括号MainMenu
。这就是为什么您会收到“ undefined reference ”错误的原因。文件末尾还有一个额外的}
。基本上,MainMenu
之后的所有函数都嵌套在MainMenu
中。
关于c - 未定义对 `FindTheVolumeAndSurfaceArea'的引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47364814/