forked from Aerin2805/Hacktoberfest2022-DSA-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.c
39 lines (35 loc) · 797 Bytes
/
Calculator.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(int argc, char *argv[])
{
float valueOne;
float valueTwo;
char operator;
float answer;
printf("Enter calculation:\n\n");
scanf("%f %c %f", &valueOne, &operator, & valueTwo);
switch(operator)
{
case '/': answer = valueOne/valueTwo;
break;
case '*': answer = valueOne*valueTwo;
break;
case '+': answer = valueOne+valueTwo;
break;
case '-': answer = valueOne-valueTwo;
break;
case '^': answer = pow(valueOne,valueTwo);
break;
case ' ': answer = sqrt(valueTwo);
break;
default: goto fail;
}
printf("%.9g%c%.9g = %.6g\n\n",valueOne,operator, valueTwo, answer);
goto exit;
fail:
printf("Fail.\n");
exit:
return 0;
}