@ -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,48 +111,46 @@ void executeTrigonometricFunction(double num) {
}
}
int scientificMode ( ) {
double num , result ;
void executeScientificFunction ( double num , int choice ) {
double result ;
int choice ;
do {
printf ( " Enter a number: " ) ;
scanf ( " %lf " , & num ) ; / / scan the number from the user
switch ( choice ) {
case 1 : / / Square root
result = squareRootFunction ( num ) ;
printf ( " Result: %lf \n " , result ) ;
break ;
choice = getScientificModeChoice ( ) ;
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 2 : / / Exponential
result = exponentialFunction ( num ) ;
printf ( " Result: %lf \n " , result ) ;
break ;
case 3 : / / Logarithm
executeLogarithmFunction ( num ) ;
break ;
case 3 : / / Logarithm
executeLogarithm Function ( num ) ;
break ;
case 4 : / / Trigonometric
executeTrigonometric Function( num ) ;
break ;
case 4 : / / Trigonometric
executeTrigonometricFunction ( num ) ;
break ;
case 0 : / / Exit the loop
break ;
case 0 : / / Exit the loop
break ;
default :
printf ( " Invalid choice. Please try again. \n " ) ;
}
}
default :
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 ;