-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathCalc.c
31 lines (27 loc) · 826 Bytes
/
Calc.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
#include <stdio.h>
int main() {
char operator;
double firstone, secondone;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operator);
printf("Enter two operands: ");
scanf("%lf %lf", &firstone, &secondone);
switch (operator) {
case '+':
printf("%.1lf + %.1lf = %.1lf", firstone, secondone, firstone + secondone);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf", firstone, secondone, firstone - secondone);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf", firstone, secondone, firstone * secondone);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf", firstone, secondone, firstone / secondone);
break;
// operator doesn't match any case constant here !
default:
printf("Error! operator is not correct !");
}
return 0;
}