Browse Source

Integrate additional mathematical functions into the scientific calculator and also a do loop to change between modes.

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

81
src/main/c/scientificMode.c

@ -1,8 +1,8 @@
// scientificMode
#include "taschenrechner.h"
#include <math.h>
#include <stdio.h>
#include <math.h>
#include "taschenrechner.h"
int scientificMode(){
@ -10,62 +10,109 @@ int scientificMode() {
int choice;
do {
printf("Enter a number: ");
scanf("%lf", &num); // scan the number from user
scanf("%lf", &num); // scan the number from the user
printf("Scientific mode Options:\n");
printf("1: Square root\n");
printf("2: Exponential\n");
printf("3: Logarithm\n");
printf("4: Trigonometric\n");
printf("0: Exit\n");
scanf("%d", &choice); // user choice
int logChoice, trigChoice; // Move the initialization outside the loops
switch(choice) {
case 1: // Square root
result = squareRootFunction(num);
printf("Result: %lf\n", result);
break;
case 2: // Exponential
result = exponentialFunction(num);
printf("Result: %lf\n", result);
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);
break;
case 4: // Trigonometric
do {
printf("Trigonometric functions:\n");
printf("5: Sine\n");
printf("6: Cosine\n");
printf("7: Tangent\n");
int trigChoice;
printf("1: Sine\n");
printf("2: Cosine\n");
printf("3: Tangent\n");
printf("0: Exit Trigonometric Menu\n");
scanf("%d", &trigChoice);
switch(trigChoice) {
case 5: // Sine
result = sin(num);
case 1: // Sine
result = sineFunction(num);
printf("Result: %lf\n", result);
break;
case 6: // Cosine
result = cos(num);
case 2: // Cosine
result = cosineFunction(num);
printf("Result: %lf\n", result);
break;
case 7: // Tangent
result = tan(num);
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.\n");
return -1; // Return an error code to indicate failure
printf("Invalid trigonometric function choice. Please try again.\n");
}
} while (trigChoice != 0);
break;
case 0: // Exit the loop
break;
default:
printf("Invalid choice. Please try again.\n");
return -1; // Return an error code to indicate failure
}
printf("Result: %lf\n", result);
} while (choice != 0);
return result;
}
Loading…
Cancel
Save