diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a9449fb --- /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..524f0ee 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; + float result; + int line = 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..6cf97c0 100644 --- a/operators.c +++ b/operators.c @@ -1,16 +1,14 @@ #include "operators.h" - -int add(int op1, int op2) { - return op1+op2; +float add(int op1, int op2) { + return (float)op1+op2; } -int minus(int op1, int op2) { - return op1-op2; +float minus(int op1, int op2) { + return (float)op1-op2; } -int mul(int op1, int op2) { - return op1*op2; +float mul(int op1, int op2) { + return (float)op1*op2; } - -int div(int op1, int op2) { - return op1%op2; +float div(int op1, int op2) { + return (float)op1/op2; } diff --git a/operators.h b/operators.h index bd08f7d..5fbed90 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); +float add(int op1, int op2); +float mul(int op1, int op2); +float div(int op1, int op2); +float 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