From 0bff2a47a8a84741c05330d90011abf3515c5ab0 Mon Sep 17 00:00:00 2001 From: Ulriche Nguefack Date: Wed, 7 Feb 2024 14:21:48 +0100 Subject: [PATCH] refactoring: entry-into-switch --- src/main/c/Calculator/calculator.c | 49 ++---------------------------- 1 file changed, 2 insertions(+), 47 deletions(-) diff --git a/src/main/c/Calculator/calculator.c b/src/main/c/Calculator/calculator.c index 4f4ea4d..bd6cdf3 100644 --- a/src/main/c/Calculator/calculator.c +++ b/src/main/c/Calculator/calculator.c @@ -70,56 +70,11 @@ double combination(int n, int r); printf("19. Combination\n"); printf("20. Exit\n"); } - double add(double num1, double num2) { - return num1 + num2; - } - - double subtract(double num1, double num2) { - return num1 - num2; - } - double multiply(double num1, double num2) { - return num1 * num2; - } - double divide(double num1, double num2) { - return num1 / num2; - } - - double exponent(double base, double exponent) { - return pow(base, exponent); - } - - double modulus(double num1, double num2) { - return fmod(num1, num2); - } + double performOperation(int choice, double num1, double num2) { + switch (choice) { - double logarithm(double num) { - return log(num); - } - - double potential(double base, double exponent) { - return pow(base, exponent); - } - double squareRoot(double num) { - return sqrt(num); - } - double square(double num) { - return num * num; - } - - double cube(double num) { - return num * num * num; - } - double cubeRoot(double num) { - return cbrt(num); - }double factorial(double num) { - if (num == 0) { - return 1; - } else { - return num * factorial(num - 1); - } - } double power(double base, double exponent) { return pow(base, exponent);