From 54d7fbb0f634723f560d93d3b024d8ecc98b4117 Mon Sep 17 00:00:00 2001 From: fdai7782 Date: Tue, 6 Feb 2024 17:06:23 +0000 Subject: [PATCH] refactoring: Extracted the trigonometric function from the scientificMode and moved in the executeTrigonometricFunction --- src/main/c/scientificMode.c | 66 ++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/src/main/c/scientificMode.c b/src/main/c/scientificMode.c index a95495e..ddf2c7e 100644 --- a/src/main/c/scientificMode.c +++ b/src/main/c/scientificMode.c @@ -38,6 +38,40 @@ void executeLogarithmFunction(double num) { } while (logChoice != 0); } +// Trigonometric +void executeTrigonometricFunction(double num) { + int trigChoice; + + do { + printf("Trigonometric functions:\n"); + printf("1: Sine\n"); + printf("2: Cosine\n"); + printf("3: Tangent\n"); + printf("0: Exit Trigonometric Menu\n"); + scanf("%d", &trigChoice); + + switch (trigChoice) { + case 1: // Sine + printf("Result: %lf\n", sineFunction(num)); + break; + + case 2: // Cosine + printf("Result: %lf\n", cosineFunction(num)); + break; + + case 3: // Tangent + printf("Result: %lf\n", tangentFunction(num)); + break; + + case 0: // Exit the trigonometric menu + break; + + default: + printf("Invalid trigonometric function choice. Please try again.\n"); + } + } while (trigChoice != 0); +} + int scientificMode(){ @@ -76,37 +110,7 @@ int scientificMode(){ break; case 4: // Trigonometric - do { - printf("Trigonometric functions:\n"); - printf("1: Sine\n"); - printf("2: Cosine\n"); - printf("3: Tangent\n"); - printf("0: Exit Trigonometric Menu\n"); - scanf("%d", &trigChoice); - - switch(trigChoice) { - case 1: // Sine - result = sineFunction(num); - printf("Result: %lf\n", result); - break; - - case 2: // Cosine - result = cosineFunction(num); - printf("Result: %lf\n", result); - break; - - case 3: // Tangent - result = tangentFunction(num); - printf("Result: %lf\n", result); - break; - - case 0: // Exit the trigonometric menu - break; - - default: - printf("Invalid trigonometric function choice. Please try again.\n"); - } - } while (trigChoice != 0); + executeTrigonometricFunction(num); break; case 0: // Exit the loop