-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathT01-Binary_Calculator.c
73 lines (51 loc) · 1.36 KB
/
T01-Binary_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* C program to create Simple Calculator using switch case
*/
#include <stdio.h>
int main()
{
char op;
float num1, num2, result= 0f ;
// float a = 0.2f +
/* Print welcome message */
printf("WELCOME TO SIMPLE CALCULATOR\n");
printf("----------------------------\n");
printf("Enter [number 1] [+ - * /] [number 2]\n");
/* Input two number and operator from user */
scanf("%f %c %f", &num1, &op, &num2);
printf("\nGot the following:\n-num1: %f\n-op: %c\n-num2: %f", num1, op, num2);
switch(op)
{
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
default:
printf("Invalid input");
}
/*
/* Switch the value and perform action based on operator*/
// switch(op)
// {
// case '+':
// result = num1 + num2;
// break;
// case '-':
// result = num1 - num2;
// break;
// case '*':
// result = num1 * num2;
// break;
// case '/':
// result = num1 / num2;
// break;
// default:
// printf("Invalid operator");
// }
// */
/* Prints the result */
printf("\n\n%.2f %c %.2f = %.2f\n", num1, op, num2, result);
return 0;
}