From a1cd5bd996e0b8ceae2e7abdd001ddf28314697b Mon Sep 17 00:00:00 2001 From: fdai7782 Date: Tue, 6 Feb 2024 19:31:47 +0000 Subject: [PATCH] refactoring: made an extra function(getOperatorInput) which helps read and print user's operation value in a single step --- src/main/c/programmingMode.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/c/programmingMode.c b/src/main/c/programmingMode.c index a5effcc..6a63556 100644 --- a/src/main/c/programmingMode.c +++ b/src/main/c/programmingMode.c @@ -13,6 +13,14 @@ int getIntegerInput(const char* prompt) { return num; } +// Display the diffrent operations and scan them +char getOperatorInput() { + char operator; + printf("Enter operator (+, -, *, /): "); + scanf(" %c", &operator); + return operator; +} + // Calculation int performOperation(int num1, char operator, int num2) { switch (operator) { @@ -40,10 +48,7 @@ void programmingMode() { char operator; num1 = getIntegerInput("Enter first integer: "); - - printf("Enter operator (+, -, *, /): "); - scanf(" %c", &operator); - + operator = getOperatorInput(); num2 = getIntegerInput("Enter second integer: "); // Calculation + Display the result