Browse Source

added BasicMode.c and refractoring to testForOperator/taschenrechner.h

remotes/origin/feature
Enrico Schellenberger 11 months ago
parent
commit
a3cbfd7de1
  1. 64
      src/main/c/BasicMode.c
  2. 115
      src/main/c/taschenrechner.h
  3. 28
      src/main/c/testForOperator.c

64
src/main/c/BasicMode.c

@ -1,8 +1,56 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "taschenrechner.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "taschenrechner.h"
void BasicMode() {
char endtmp = '0'; //0 false, 1 true
double result = 0;
double numbers[100] = {0.0};
char operatoren[100];
do {
//100 doubles in this array goes through the for loop till 100 numbers or = is entered
for (int i = 0; i < 100) {
printf("Enter a Number: ");
numbers[i] = testForNumber(); //gets number
printf("Enter a operation: ");
operator[i] = testForOperator(); //gets operator
if (i > 1) { //if function to prevent numbers[-1]
switch (operator[i]) //checks of the operator and switches to the case with the needed function
{
case '+':
result += add(numbers[i - 1], numbers[i])
break;
case '-':
result += minus(numbers[i - 1], numbers[i])
break;
case '*':
result += multiply(numbers[i - 1], numbers[i])
break;
case '/':
result += divide(numbers[i - 1], numbers[i])
break;
case '=':
printf("The result is: %d", result);
endtmp = 1;
break;
default:
break;
}
}
i++;
}
} while (endtmp != '1')
}

115
src/main/c/taschenrechner.h

@ -1,56 +1,59 @@
#ifndef TASCHENRECHNER_H
#define TASCHENRECHNER_H
//add function
doulbe add(doulbe a, doulbe b);
//minus function
doulbe minus(doulbe a, doulbe b);
//multiply function
doulbe multiply(doulbe a, doulbe b);
//divide function
doulbe divide(doulbe a, doulbe b);
//get input and check if its a number
double testForNumber()
// Square root function
double squareRootFunction(double x);
//..
// Trigonometric functions
double sineFunction(double angle);
double cosineFunction(double angle);
double tangentFunction(double angle);
//..
// Logarithmic functions
double logarithmFunction(double x);
double naturalLogarithmFunction(double x);
double logarithmBase2Function(double x);
//..
// Exponential function
double exponentialFunction(double x);
// ..
// Bitwise AND function
int bitwiseAND(int num1, int num2);
// Bitwise OR function
int bitwiseOR(int num1, int num2);
// Bitwise XOR function
int bitwiseXOR(int num1, int num2);
int mode(int userChoice);
int displayMenu();
#endif // TASCHENRECHNER_H
#ifndef TASCHENRECHNER_H
#define TASCHENRECHNER_H
//add function
doulbe add(doulbe a, doulbe b);
//minus function
doulbe minus(doulbe a, doulbe b);
//multiply function
doulbe multiply(doulbe a, doulbe b);
//divide function
doulbe divide(doulbe a, doulbe b);
//get input and check if its a number
double testForNumber()
//get input and check if its a operator
char testForOperator()
// Square root function
double squareRootFunction(double x);
//..
// Trigonometric functions
double sineFunction(double angle);
double cosineFunction(double angle);
double tangentFunction(double angle);
//..
// Logarithmic functions
double logarithmFunction(double x);
double naturalLogarithmFunction(double x);
double logarithmBase2Function(double x);
//..
// Exponential function
double exponentialFunction(double x);
// ..
// Bitwise AND function
int bitwiseAND(int num1, int num2);
// Bitwise OR function
int bitwiseOR(int num1, int num2);
// Bitwise XOR function
int bitwiseXOR(int num1, int num2);
int mode(int userChoice);
int displayMenu();
#endif // TASCHENRECHNER_H

28
src/main/c/testForOperator.c

@ -0,0 +1,28 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "taschenrechner.h"
char testForOperator() {
//saving the number of operators in a variable so it only needs to be changed in one location
int numberOfOperators = 5;
//array where all valid Operators are saved, can be esily expanded
char oppArray[numberOfOperators] = { '+','-','*','/','=' };
char input;
bool validInput = false;
//Loops as long as input isn't valid, enters at least one time
while (!validInput) {
scanf_s("%c\n", &input);
//checks every position of the array if a position is equal to input returns the input, which also stopps the function
for (int i = 0; i <= numberOfOperators; i++) {
if (input == oppArray[i]) {
return input;
}
}
//if the input was deemed invalid it asks for new input and goes to the top of the while loop
printf("Diese Eigabe war nicht zulässig probieren sie es noch einmal!\n");
}
}
Loading…
Cancel
Save