-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path12_SwitchCase.c
More file actions
38 lines (30 loc) · 786 Bytes
/
12_SwitchCase.c
File metadata and controls
38 lines (30 loc) · 786 Bytes
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
// Program to create a simple calculator
#include <stdio.h>
int main()
{
char operation;
double n1, n2;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operation);
printf("Enter two operands: ");
scanf("%lf %lf", &n1, &n2);
switch (operation)
{
case '+':
printf("%.1lf + %.1lf = %.1lf", n1, n2, n1 + n2);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf", n1, n2, n1 - n2);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf", n1, n2, n1 * n2);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf", n1, n2, n1 / n2);
break;
// operator doesn't match any case constant +, -, *, /
default:
printf("Error! operator is not correct");
}
return 0;
}