2017-11-18 147 views
-1

大家好, 当我试图执行和编译我的代码未定义的参考`FindTheVolumeAndSurfaceArea”

#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 
在搞什么鬼

正在进行?!我尝试解决了很多时间,但我不能 感谢, IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII

+0

这里有很多问题 - 函数只能执行一个'return'语句;'MainMenu'和'FindTheVolumeAndSurfaceArea'不断地相互调用; 'FindTheVolumeAndSurfaceArea'函数不返回任何东西,虽然签名表示它返回一个'double'等等......从一本关于C. – babon

+0

'的好书开始,while(choice!= 3);' - 未定义的var访问。然后大量的其他错误。你不应该让你的代码到达这个阶段!编写返回虚拟值的main()和接近空的函数。测试/调试。在lthat编译和测试之前不要添加更多内容。这个来源有太多的语法,逻辑,范围和其他错误,因此在SO Q&A中修复并不明智。 –

回答

0

你在MainMenu年底缺少右大括号}。这就是为什么你会收到“未定义的参考”错误。文件末尾还有一个额外的}。基本上MainMenu之后的所有功能都嵌套在MainMenu之内。