From 941e7584b7eb78b0c890fea7cea4f5b4772e0fc2 Mon Sep 17 00:00:00 2001 From: fdai7782 Date: Tue, 6 Feb 2024 19:28:41 +0000 Subject: [PATCH] refactoring: made an extra function(getIntegerInput) which helps read and print user value in a single step --- src/main/c/programmingMode.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/c/programmingMode.c b/src/main/c/programmingMode.c index 42c5c61..a5effcc 100644 --- a/src/main/c/programmingMode.c +++ b/src/main/c/programmingMode.c @@ -5,6 +5,14 @@ #include "taschenrechner.h" +// get the NUmbers from the user +int getIntegerInput(const char* prompt) { + int num; + printf("%s", prompt); + scanf("%d", &num); + return num; +} + // Calculation int performOperation(int num1, char operator, int num2) { switch (operator) { @@ -31,14 +39,12 @@ void programmingMode() { int num1, num2, result; char operator; - printf("Enter first integer: "); - scanf("%d", &num1); + num1 = getIntegerInput("Enter first integer: "); printf("Enter operator (+, -, *, /): "); scanf(" %c", &operator); - printf("Enter second integer: "); - scanf("%d", &num2); + num2 = getIntegerInput("Enter second integer: "); // Calculation + Display the result