Answered step by step
Verified Expert Solution
Question
1 Approved Answer
got a calculator code but it is not working and i dont understand why. Enter an operator ( + , - , * , /
got a calculator code but it is not working and i dont understand why.
Enter an operator sin cos tan log sqrt pow: log
Enter a number: l
didnt even enter a number it just happenning like that. Or doing like
Enter an operator sin cos tan log sqrt pow: sin
Enter a number: s
cant write a number.
#include
#include
Function declarations
double adddouble num double num;
double subtractdouble num double num;
double multiplydouble num double num;
double dividedouble num double num;
double sinedouble angle;
double cosinedouble angle;
double tangentdouble angle;
double logarithmdouble num;
double squareRootdouble num;
double powerdouble base, double exponent;
int main
char op;
double num num result;
printfEnter an operator sin cos tan log sqrt pow: ;
scanfc &op;
if op s && op c && op t && op l && op q
For binary operations, prompt for two numbers
printfEnter two numbers: ;
scanflf lf &num #
else
For unary operations, prompt for one number
printfEnter a number: ;
scanflf #
num; Set num to for unary operations
switch op
case :
result addnum num;
break;
case :
result subtractnum num;
break;
case :
result multiplynum num;
break;
case :
if num
printfError: Division by zero
;
return ; Exit with an error code
else
result dividenum num;
break;
case s:
result sinenum;
break;
case c:
result cosinenum;
break;
case t:
result tangentnum;
break;
case l:
if num
result logarithmnum;
else
printfError: Logarithm undefined for nonpositive numbers
;
return ;
break;
case q:
if num
result squareRootnum;
else
printfError: Square root undefined for negative numbers
;
return ;
break;
case p:
result powernum num;
break;
default:
printfInvalid operator
;
return ;
printflf c lf lf
num op num result;
return ;
Function definitions
double adddouble num double num
return num num;
double subtractdouble num double num
return num num;
double multiplydouble num double num
return num num;
double dividedouble num double num
return num num;
double sinedouble angle
return sinangle MPI ;
double cosinedouble angle
return cosangle MPI ;
double tangentdouble angle
return tanangle MPI ;
double logarithmdouble num
return lognum;
double squareRootdouble num
return sqrtnum;
double powerdouble base, double exponent
return powbase exponent;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started