|
|
@ -6,3 +6,51 @@ |
|
|
|
#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') |
|
|
|
|
|
|
|
} |