Browse Source

refactoring: Split scientificMode into two functions: scientificMode (for setup) and executeScientificFunction (handling switch case and result output). Also, isolated user's calculation choice into getNumberFromUser.

remotes/origin/kabrel
fdai7782 11 months ago
parent
commit
cb1e99442f
  1. 36
      src/main/c/scientificMode.c

36
src/main/c/scientificMode.c

@ -4,6 +4,14 @@
#include <math.h> #include <math.h>
#include "taschenrechner.h" #include "taschenrechner.h"
// get the number which has to be calculated
double getNumberFromUser() {
double num;
printf("Enter a number: ");
scanf("%lf", &num);
return num;
}
// Choice for ScientificMode // Choice for ScientificMode
int getScientificModeChoice() { int getScientificModeChoice() {
int choice; int choice;
@ -103,22 +111,10 @@ void executeTrigonometricFunction(double num) {
} }
int scientificMode(){
double num, result;
int choice;
do {
printf("Enter a number: ");
scanf("%lf", &num); // scan the number from the user
choice = getScientificModeChoice();
int logChoice, trigChoice; // Move the initialization outside the loops
void executeScientificFunction(double num, int choice) {
double result;
switch (choice) { switch (choice) {
case 1: // Square root case 1: // Square root
result = squareRootFunction(num); result = squareRootFunction(num);
printf("Result: %lf\n", result); printf("Result: %lf\n", result);
@ -142,9 +138,19 @@ int scientificMode(){
default: default:
printf("Invalid choice. Please try again.\n"); printf("Invalid choice. Please try again.\n");
} }
}
// scientificMode
double scientificMode() {
double result;
int choice;
do {
double num = getNumberFromUser();
choice = getScientificModeChoice();
executeScientificFunction(num, choice);
} while (choice != 0); } while (choice != 0);
return result; return result;
Loading…
Cancel
Save