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