Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
/calc
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Simple Calculator

This is a buggy application that will be used for Lab5 of 'Introduction to Open Source Software Development.'

- Fork the project.
- Create a topic branch from master.
- The branch name must be your student id. (e.g. 201624000)
- Make some commits to improve the project.
- Fix the well-knwon bugs.
- Remove object and binary files.
- Add .gitignore file
- Push this branch to your GitHub project.
- Open a Pull Request on GitHub.
- The Pull Request must be submitted to master branch of Classroom-IOSSD/SimpleCalculator!
- Capture the Pull Request and upload it to PLMS.

15 changes: 8 additions & 7 deletions calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@ int main(){
FILE *fp = NULL;
int operand1, operand2;
char operator = ' ';
int result, line = 0;
float result, line = 0;

fp = fopen("read.txt","r");
if(fp!=NULL){
fscanf(fp, "%d", &line);
fscanf(fp, "%f", &line);

for(int i=0; i<line; i++) {
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);
}
}
Expand Down
10 changes: 5 additions & 5 deletions operators.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "operators.h"

int add(int op1, int op2) {
double add(int op1, int op2) {
return op1+op2;
}
int minus(int op1, int op2) {
double minus(int op1, int op2) {
return op1-op2;
}
int mul(int op1, int op2) {
double mul(int op1, int op2) {
return op1*op2;
}

int div(int op1, int op2) {
return op1%op2;
double div(float op1, float op2) {
return op1/op2;
}

8 changes: 4 additions & 4 deletions operators.h
Original file line number Diff line number Diff line change
@@ -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(float op1, float op2);
double minus(int op1, int op2);
2 changes: 1 addition & 1 deletion read.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
5
4
123 + 456
234 * 234
143 - 111
Expand Down