-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator_fun.c
71 lines (60 loc) · 1.19 KB
/
calculator_fun.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
#include<stdio.h>
float Add(float a, float b)
{
return a + b;
}
float Subtract(float a, float b)
{
return a - b;
}
float multiply(float a, float b)
{
return a*b;
}
float divide(float a, float b)
{
if (a != 0)
{
return a/b;
}
else{
printf("Eror: Can not divide number by ZERO. \n");
return 0;
}
}
int main()
{
char operator;
float num, result = 0;
scanf("%f", &result);
do {
scanf(" %c", &operator);
if (operator == 'q' || operator == 'Q')
{
break;
}
scanf("%f", &num);
switch (operator)
{
case '+':
result = Add(result, num);
break;
case '-':
result = Subtract(result, num);
break;
case '*':
result = multiply(result, num);
break;
case '/':
result = divide(result, num);
break;
default:
printf("Invalid operator, please enter a valid operator.. ");
continue;
}
printf("Result = %.1f", result);
}
while (1);
printf("Calculator Exoted..");
return 0;
}