From de0436173724344a317656693f21de17d058efdc Mon Sep 17 00:00:00 2001 From: fdai7782 Date: Tue, 6 Feb 2024 16:52:31 +0000 Subject: [PATCH] refactoring: Extracted the logarithm function from the scientificMode and moved in the executeScientificFunction --- src/main/c/scientificMode.c | 67 ++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/main/c/scientificMode.c b/src/main/c/scientificMode.c index 88b69f7..a95495e 100644 --- a/src/main/c/scientificMode.c +++ b/src/main/c/scientificMode.c @@ -4,6 +4,41 @@ #include #include "taschenrechner.h" +// Logarithm +void executeLogarithmFunction(double num) { + int logChoice; + + do { + printf("Logarithm Options:\n"); + printf("1: Logarithm (base 10)\n"); + printf("2: Natural Logarithm (ln)\n"); + printf("3: Logarithm (base 2)\n"); + printf("0: Exit Logarithm Menu\n"); + scanf("%d", &logChoice); + + switch (logChoice) { + case 1: // Logarithm (base 10) + printf("Result: %lf\n", logarithmFunction(num)); + break; + + case 2: // Natural Logarithm (ln) + printf("Result: %lf\n", naturalLogarithmFunction(num)); + break; + + case 3: // Logarithm (base 2) + printf("Result: %lf\n", logarithmBase2Function(num)); + break; + + case 0: // Exit the logarithm menu + break; + + default: + printf("Invalid logarithm function choice. Please try again.\n"); + } + } while (logChoice != 0); +} + + int scientificMode(){ double num, result; @@ -37,37 +72,7 @@ int scientificMode(){ break; case 3: // Logarithm - do { - printf("Logarithm Options:\n"); - printf("1: Logarithm (base 10)\n"); - printf("2: Natural Logarithm (ln)\n"); - printf("3: Logarithm (base 2)\n"); - printf("0: Exit Logarithm Menu\n"); - scanf("%d", &logChoice); - - switch(logChoice) { - case 1: // Logarithm (base 10) - result = logarithmFunction(num); - printf("Result: %lf\n", result); - break; - - case 2: // Natural Logarithm (ln) - result = naturalLogarithmFunction(num); - printf("Result: %lf\n", result); - break; - - case 3: // Logarithm (base 2) - result = logarithmBase2Function(num); - printf("Result: %lf\n", result); - break; - - case 0: // Exit the logarithm menu - break; - - default: - printf("Invalid logarithm function choice. Please try again.\n"); - } - } while (logChoice != 0); + executeLogarithmFunction(num); break; case 4: // Trigonometric