|
|
@ -2,58 +2,20 @@ |
|
|
|
#include <string.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <math.h> |
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
|
|
|
// convert decimal to binary |
|
|
|
long long int DecToBin(long long int n) { |
|
|
|
long long int bin = 0; |
|
|
|
long long int rem, i = 1; |
|
|
|
|
|
|
|
while (n != 0) { |
|
|
|
rem = n % 2; |
|
|
|
bin += rem * i; |
|
|
|
i *= 10; |
|
|
|
n /= 2; |
|
|
|
} |
|
|
|
|
|
|
|
void BasicMode() { |
|
|
|
char endtmp = '0'; //0 false, 1 true |
|
|
|
double result = 0; |
|
|
|
double numbers[100] = {0.0}; |
|
|
|
char operators[100]; |
|
|
|
|
|
|
|
do { |
|
|
|
//100 doubles in this array goes through the for loop till 100 numbers or = is entered |
|
|
|
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'); |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
} |
|
|
|
// for all calculations we take the number and the number before that |
|
|
|
else { // and do the operation |
|
|
|
result += multiply(numbers[i - 1], numbers[i]); //multiplys if char is * and adds number to the result |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if ((operators[i] == '+' || operators[i] == '-') && i > 1) { |
|
|
|
if (operators[i] == '+') { |
|
|
|
result += add(numbers[i - 1], numbers[i]); //adds if char is + and adds number to the result |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
result += minus(numbers[i - 1], numbers[i]); //subtrakts if char is - and adds number to the result |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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 (operators[i] == '=') { //if char is = |
|
|
|
printf("The result is: %f", result); //print out the result |
|
|
|
i = 100; |
|
|
|
break; |
|
|
|
} |
|
|
|
i++; |
|
|
|
} |
|
|
|
return bin; |
|
|
|
} |