-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
這裏有很多問題 - 函數只能執行一個'return'語句;'MainMenu'和'FindTheVolumeAndSurfaceArea'不斷地相互調用; 'FindTheVolumeAndSurfaceArea'函數不返回任何東西,雖然簽名表示它返回一個'double'等等......從一本關於C. – babon
'的好書開始,while(choice!= 3);' - 未定義的var訪問。然後大量的其他錯誤。你不應該讓你的代碼到達這個階段!編寫返回虛擬值的main()和接近空的函數。測試/調試。在lthat編譯和測試之前不要添加更多內容。這個來源有太多的語法,邏輯,範圍和其他錯誤,因此在SO Q&A中修復並不明智。 –