高级科学计算器使用c中的函数

时间:2015-10-04 11:57:38

标签: c calculator

我试图制作一个高级计算器,但它有一些运行时错误,我无法解决它..代码工作...但有一些运行时错误。我试图让它工作,但无论我尝试什么,错误存在。我甚至尝试过使用开关盒。

 #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);
      }

1 个答案:

答案 0 :(得分:0)

第123行调用的log2()函数未在代码中定义。要解决此问题,您必须定义此功能。

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