Skip to content

Commit a7f7778

Browse files
authored
Calculator
1 parent c5c05c2 commit a7f7778

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

Calculator

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
5+
char operator;
6+
7+
double first, second;
8+
9+
printf("Enter an operator (+, -, *,): ");
10+
11+
scanf("%c", &operator);
12+
13+
printf("Enter two operands: ");
14+
15+
scanf("%lf %lf", &first, &second);
16+
17+
switch (operator) {
18+
19+
case '+':
20+
21+
printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
22+
23+
break;
24+
25+
case '-':
26+
27+
printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
28+
29+
break;
30+
31+
case '*':
32+
33+
printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
34+
35+
break;
36+
37+
case '/':
38+
39+
printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
40+
41+
break;
42+
43+
// operator doesn't match any case constant
44+
45+
default:
46+
47+
printf("Error! operator is not correct");
48+
49+
}
50+
51+
return 0;
52+
53+
}

0 commit comments

Comments
 (0)