diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2490a4d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +/calc diff --git a/calc b/calc deleted file mode 100755 index 023ec18..0000000 Binary files a/calc and /dev/null differ diff --git a/calc.c b/calc.c index 85f1466..f3b00e2 100644 --- a/calc.c +++ b/calc.c @@ -5,7 +5,8 @@ int main(){ FILE *fp = NULL; int operand1, operand2; char operator = ' '; - int result, line = 0; + int line = 0; + double result =0; fp = fopen("read.txt","r"); if(fp!=NULL){ @@ -15,18 +16,19 @@ int main(){ fscanf(fp, "%d %c %d",&operand1, &operator, &operand2); switch(operator) { case '+': - result = add(operand1, operator); + result = add(operand1, operand2); break; case '-': - result = minus(operand1, operator); + result = minus(operand1, operand2); break; case '*': - result = mul(operand1, operator); + result = mul(operand1, operand2); + break; case '/': - result = div(operand1, operator); + result = div(operand1, operand2); break; } - printf("%d %c %d = %d\n", + printf("%d %c %d = %f\n", operand1, operator, operand2, result); } } diff --git a/calc.o b/calc.o deleted file mode 100644 index e2bf1e7..0000000 Binary files a/calc.o and /dev/null differ diff --git a/operators.c b/operators.c index d51cb3e..fda2eb3 100644 --- a/operators.c +++ b/operators.c @@ -1,16 +1,20 @@ #include "operators.h" -int add(int op1, int op2) { - return op1+op2; +double add(int op1, int op2) { + double k = op1+op2; + return k; } -int minus(int op1, int op2) { - return op1-op2; +double minus(int op1, int op2) { + double k = op1-op2; + return k; } -int mul(int op1, int op2) { - return op1*op2; +double mul(int op1, int op2) { + double k = op1*op2; + return k; } -int div(int op1, int op2) { - return op1%op2; +double div(double op1, double op2) { + double k = op1/op2; + return k; } diff --git a/operators.h b/operators.h index bd08f7d..2bd3672 100644 --- a/operators.h +++ b/operators.h @@ -1,4 +1,4 @@ -int add(int op1, int op2); -int mul(int op1, int op2); -int div(int op1, int op2); -int minus(int op1, int op2); +double add(int op1, int op2); +double mul(int op1, int op2); +double div(double op1, double op2); +double minus(int op1, int op2); diff --git a/operators.o b/operators.o deleted file mode 100644 index 71b996c..0000000 Binary files a/operators.o and /dev/null differ diff --git a/read.txt b/read.txt index 3e2bf01..8c26ad2 100644 --- a/read.txt +++ b/read.txt @@ -1,4 +1,4 @@ -5 +4 123 + 456 234 * 234 143 - 111