From 310d9bb3578a686ab667428937570c653392ecb7 Mon Sep 17 00:00:00 2001 From: Ulriche Nguefack Date: Wed, 7 Feb 2024 14:16:46 +0100 Subject: [PATCH] refactoring: if-statement2 --- src/main/c/Calculator/calculator.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/c/Calculator/calculator.c b/src/main/c/Calculator/calculator.c index 13c4174..4f4ea4d 100644 --- a/src/main/c/Calculator/calculator.c +++ b/src/main/c/Calculator/calculator.c @@ -31,6 +31,16 @@ double combination(int n, int r); num1 = n; num2 = r; } + if (choice != 4 || (choice == 4 && num2 != 0)) { + result = performOperation(choice, num1, num2); + printf("Result: %.2lf\n", result); + } else { + printf("Error: Division by zero\n"); + } + } else if (choice != 20) { + printf("Invalid choice\n"); + } + } while (choice != 20);