[英]Advanced Scientific Calculator using functions in c
I Tried to make an advanced calculator, but it's having some run time error and i am not able to figure it out.. code works... but with some run time error.我试图制作一个高级计算器,但它有一些运行时错误,我无法弄清楚......代码有效......但有一些运行时错误。 I am trying to make it work, but not matter what i try, the error exists.我正在努力使其工作,但无论我尝试什么,错误都存在。 i have even tried using switch case.我什至尝试过使用开关盒。
#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);
}
The log2()
function called on line 123 is not defined in the code.代码中没有定义第 123 行调用的log2()
函数。 To solve this, you must define this function.为了解决这个问题,你必须定义这个函数。
float log2(float x)
{
/// add code here.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.