2015-10-04 50 views
-5

功能,我試圖讓一個先進的計算器,但它有一些運行時錯誤,我無法弄清楚..代碼工作......但也有一些運行時錯誤。我試圖讓它工作,但無論我嘗試什麼,都存在錯誤。我甚至嘗試過使用開關盒。先進的科學計算器使用在C

#include<stdio.h> 
#include<math.h> 
#define PI 3.14159265 
float sine(float x); 
float cosine(float x); 
float tangent(float x); 
float exponent(float x); 
float logb10(float x); 
float logb2(float x); 
float power(float x, float y); 
float fmodu(float x, float y); 

int main() 
{ 
    int n; 
    float x,y,z; 
    do 
    { 
    printf ("MENU\n1.SIN\n2.COS\n3.TAN\n4.EXP\n5.LOG10\n6.LOG2\n7.POW\n8.FMOD\n9.Exit\n"); 
    printf("Enter your choice:\n"); 
    scanf("%d", &n); 

if(n==1) 
{ 
    printf("Enter the degree:\n"); 
    scanf("%f", &x); 
    z=sine(x); 
    printf("sin(%.2f) = %.2f\n",x,z); 
} 

else if(n==2) 
{ 
    printf("Enter the degree:\n"); 
    scanf("%f", &x); 
    z=cosine(x); 
    printf("cos(%.2f) = %.2f\n",x,z); 
} 

    else if(n==3) 
{ 
    printf("Enter the degree:\n"); 
    scanf("%f", &x); 
    z=tangent(x); 
    printf("tan(%.2f) = %.2f\n",x,z); 
} 

    else if(n==4) 
{ 
    printf("Enter the power of e:\n"); 
    scanf("%f", &x); 
    z=exponent(x); 
    printf("e^(%.2f) = %.2f\n",x,z); 
} 

else if(n==5) 
{ 
    printf("Enter the number to find log10:\n"); 
    scanf("%f", &x); 
    z=logb10(x); 
    printf("logb10(%.2f) = %.2f\n",x,z); 
} 

else if(n==6) 
{ 
    printf("Enter the number to find log2:\n"); 
    scanf("%f", &x); 
    z=logb2(x); 
    printf("log2(%.2f) = %.2f\n",x,z); 
} 

    else if(n==7) 
{ 
    printf("Enter the base:\n"); 
    scanf("%f", &x); 
    printf("Enter the exponent:\n"); 
    scanf("%f", &y); 
    z=power(x,y); 
    printf("%.2fd^%.2f = %.2f\n", x,y,z); 
} 

    else if(n==8) 
{ 
    printf("Enter the number:\n"); 
    scanf("%f", &x); 
    printf("Enter the modulor:\n"); 
    scanf("%f", &y); 
    z=fmodu(x,y); 
    printf("The floating point remainder of %.2f/%.2f = %.2f\n",x,y,z); 
    } 
    }while(n!=9); 
    return 0; 
    } 

    float sine(float x) 
    { 
    return sin(x*PI/180); 
    } 

    float cosine(float x) 
    { 
    return cos(x*PI/180); 
    } 
    float tangent(float x) 
    { 
    return tan(x*PI/180); 
    } 

    float exponent(float x) 
    { 
    return exp(x); 
    } 

    float logb10(float x) 
    { 
    return log10(x); 
    } 

    float logb2(float x) 
    { 
    return log2(x); 
    } 

    float power(float x, float y) 
    { 
    return pow(x,y); 
    } 

    float fmodu(float x, float y) 
    { 
    return fmod(x,y); 
     } 
+0

你能解釋一下具體問題嗎?此外,您還可以張貼如圖所示[這裏]最小的,完整的例子(http://stackoverflow.com/help/mcve)。 – laylarenee

+0

好,謝謝!但正如我所說的...我還不確定是什麼在我的代碼,並在其中的部分問題。這就是爲什麼我完全發佈它。 –

+0

什麼行數是個例外?我傳遞什麼參數來複制它? – laylarenee

回答

0

log2()函數調用上線123中沒有的代碼所定義。要解決這個問題,你必須定義這個功能。

float log2(float x) 
{ 
    /// add code here. 
} 
+0

但我已經包含了math.h,所以使用預定義的定義我能夠找到log2的值。​​ –

+0

'log2()'可能未提供文件math.h庫 - 它不是在我提供參見[這堆棧溢出答案](http://stackoverflow.com/questions/758001/log2-not-found-in-my-math-h)獲取更多信息。 – laylarenee

+0

我沒有把它定義爲你說的,但它仍然說着同樣:( –