-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex.6.4.c
49 lines (42 loc) · 784 Bytes
/
ex.6.4.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
// Simple printing calculator
#include <stdio.h>
int main (void)
{
printf ("Begin Calculations\n");
double number, accumulator;
char operator = '\0';
while ( operator != 'E' ) {
scanf ("%lf %c", &number, &operator);
switch ( operator ) {
case '+':
accumulator += number;
break;
case '-':
accumulator -= number;
break;
case '*':
accumulator *= number;
break;
case '/':
if ( number != 0 ) {
accumulator /= number;
break;
}
else {
printf ("Division by zero\n");
continue;
}
case 'S':
accumulator = number;
break;
case 'E':
break;
default:
printf ("Unknown operator\n");
continue;
}
printf ("= %f\n", accumulator);
}
printf ("End of Calculations.\n");
return 0;
}