From 0cdc901bf4ffa6d713849369302db83adee52f67 Mon Sep 17 00:00:00 2001 From: fdai7782 Date: Wed, 7 Feb 2024 18:01:19 +0000 Subject: [PATCH] Updated the header file to calculator.h --- src/main/c/BasicMode.c | 118 ++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/src/main/c/BasicMode.c b/src/main/c/BasicMode.c index f6101c3..d1e4d5c 100644 --- a/src/main/c/BasicMode.c +++ b/src/main/c/BasicMode.c @@ -1,59 +1,59 @@ -#include -#include -#include -#include - -#include "taschenrechner.h" - - -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++; - } -} +#include +#include +#include +#include + +#include "calculator.h" + + +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++; + } +}