diff --git a/src/main/c/programmingMode.c b/src/main/c/programmingMode.c index c869b99..42c5c61 100644 --- a/src/main/c/programmingMode.c +++ b/src/main/c/programmingMode.c @@ -5,6 +5,27 @@ #include "taschenrechner.h" +// Calculation +int performOperation(int num1, char operator, int num2) { + switch (operator) { + case '+': + return num1 + num2; + case '-': + return num1 - num2; + case '*': + return num1 * num2; + case '/': + if (num2 != 0) { + return num1 / num2; + } else { + printf("Error: Division by zero\n"); + return 0; + } + default: + printf("Invalid operator\n"); + return 0; + } +} void programmingMode() { int num1, num2, result; @@ -19,30 +40,9 @@ void programmingMode() { printf("Enter second integer: "); scanf("%d", &num2); - // Calculation - switch (operator) { - case '+': - result = num1 + num2; - break; - case '-': - result = num1 - num2; - break; - case '*': - result = num1 * num2; - break; - case '/': - if (num2 != 0) { - result = num1 / num2; - } else { - printf("Error: Division by zero\n"); - result = 0; - } - break; - default: - printf("Invalid operator\n"); - result = 0; - } + // Calculation + Display the result - // Display the result + result = performOperation(num1, operator, num2); + printf("Result: %d\n", result); } \ No newline at end of file