forked from IEEE-NITK/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.c
40 lines (28 loc) · 794 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
# include <stdio.h>
int main() {
char op;
double n1,n2;
printf("Enter an operator (+, -, *,): ");
scanf("%c", &op);
printf("Enter two operands: ");
scanf("%lf %lf",&n1, &n2);
switch(op)
{
case '+':
printf("%.1lf + %.1lf = %.1lf\n",n1, n2, n1 + n2);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf\n",n1, n2, n1 - n2);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf\n",n1, n2, n1 * n2);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf\n",n1, n2, n1 / n2);
break;
// operator doesn't match any case constant (+, -, *, /)
default:
printf("Error! operator is not correct");
}
return 0;
}