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