forked from DSC-COEA-Ambajogai/Hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.c
34 lines (32 loc) · 826 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
#include <stdio.h>
int main() {
char op;
//Input Operators
double first, second;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &op);
printf("Enter two operands: ");
scanf("%lf %lf", &first, &second);
switch (op) {
case '+':
//Addition
printf("%.1lf + %.1lf = %.1lf", first, second, first + second);
break;
case '-':
//Subtraction
printf("%.1lf - %.1lf = %.1lf", first, second, first - second);
break;
case '*':
//Multiplication
printf("%.1lf * %.1lf = %.1lf", first, second, first * second);
break;
case '/':
//Division
printf("%.1lf / %.1lf = %.1lf", first, second, first / second);
break;
// operator doesn't match any case constant
default:
printf("Error! operator is not correct");
}
return 0;
}