forked from Classroom-IOSSD/SimpleCalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc.c
More file actions
35 lines (31 loc) · 672 Bytes
/
calc.c
File metadata and controls
35 lines (31 loc) · 672 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
#include <stdio.h>
#include "operators.h"
int main(){
FILE *fp = NULL;
int operand1, operand2;
char operator = ' ';
int result, line = 0;
fp = fopen("read.txt","r");
if(fp!=NULL){
fscanf(fp, "%d", &line);
for(int i=0; i<line; i++) {
fscanf(fp, "%d %c %d",&operand1, &operator, &operand2);
switch(operator) {
case '+':
result = add(operand1, operator);
break;
case '-':
result = minus(operand1, operator);
break;
case '*':
result = mul(operand1, operator);
case '/':
result = div(operand1, operator);
break;
}
printf("%d %c %d = %d\n",
operand1, operator, operand2, result);
}
}
return 0;
}