Browse Source

Fixed syntax errors in team member's code

remotes/origin/feature
fdai7782 11 months ago
parent
commit
b3773ad434
  1. 12
      src/main/c/BasicMode.c
  2. 8
      src/main/c/main_taschenrechner.c
  3. 12
      src/main/c/taschenrechner.h
  4. 5
      src/main/c/testForOperator.c

12
src/main/c/BasicMode.c

@ -14,17 +14,17 @@ void BasicMode() {
do {
//100 doubles in this array goes through the for loop till 100 numbers or = is entered
for (int i = 0; i < 100) {
for (int i = 0; i < 100; i++) {
printf("Enter a Number: ");
numbers[i] = testForNumber(); //gets number
printf("Enter a operation: ");
operators[i] = testForOperator(); //gets operator
}
} while (endtmp != '1')
} while (endtmp != '1');
for (int i = 0; i < 100) {//checks all operators to check for priority
for (int i = 0; i < 100; i++) {//checks all operators to check for priority
if ((operators[i] == '/' || operators[i] == '*') && i > 1) { //if operators[i] == / or * and i>1 so you dont get numbers[-1]
if (operators[i] == '/') {
result += divide(numbers[i - 1], numbers[i]); //divides if char is / and adds number to the result
@ -45,12 +45,12 @@ void BasicMode() {
}
}
else if (i<=1 && operator[i] == '=') { //if there are less then 2 numbers in the array
else if (i<=1 && operators[i] == '=') { //if there are less then 2 numbers in the array
result = numbers[i]; //set result to the 0 digit
}
else if (operator[i] == '=') { //if char is =
printf("The result is: %d", result); //print out the result
else if (operators[i] == '=') { //if char is =
printf("The result is: %f", result); //print out the result
i = 100;
break;
}

8
src/main/c/main_taschenrechner.c

@ -6,19 +6,19 @@
#include "taschenrechner.h"
doulbe add(doulbe a, doulbe b) {
double add(double a, double b) {
return a + b;
}
doulbe minus (doulbe a, doulbe b){
double minus (double a, double b){
return a - b;
}
doulbe multiply(doulbe a, doulbe b) {
double multiply(double a, double b) {
return a * b;
}
doulbe divide(doulbe a, doulbe b) {
double divide(double a, double b) {
if (b == 0) {
return 0;
}

12
src/main/c/taschenrechner.h

@ -2,22 +2,22 @@
#define TASCHENRECHNER_H
//add function
doulbe add(doulbe a, doulbe b);
double add(double a, double b);
//minus function
doulbe minus(doulbe a, doulbe b);
double minus(double a, double b);
//multiply function
doulbe multiply(doulbe a, doulbe b);
double multiply(double a, double b);
//divide function
doulbe divide(doulbe a, doulbe b);
double divide(double a, double b);
//get input and check if its a number
double testForNumber()
double testForNumber();
//get input and check if its a operator
char testForOperator()
char testForOperator();
// Square root function
double squareRootFunction(double x);

5
src/main/c/testForOperator.c

@ -2,6 +2,7 @@
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include "taschenrechner.h"
@ -9,7 +10,7 @@ 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 oppArray[] = { '+','-','*','/','=' };
char input;
bool validInput = false;
@ -23,6 +24,6 @@ char testForOperator() {
}
}
//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");
printf("The input was not allowed. Please try again!\n");
}
}
Loading…
Cancel
Save