src/operations.c
//this function applies operations to the postfix expression and outputs a result
this function applies operations to the postfix expression and outputs a result
this function applies operations to the postfix expression and outputs a result
int callOps(struct inputSeperate *input, int length){
    int inPos, outPos = 0;
    struct inputSeperate output[length];
    struct inputSeperate scanned;
    for (inPos = 0; inPos < length; inPos++){
        scanned = input[inPos];
        if (scanned.isOperator == 0){
            output[outPos] = scanned;
            outPos++;
        }
        else {
            double value1 = output[outPos - 2].value;
            double value2 = output[outPos - 1].value;
            if (scanned.content[0] == '+'){
                value1 = value1 + value2;
            }
            else if (scanned.content[0] == '-'){
                value1 = value1 - value2;
            }
            else if (scanned.content[0] == '*'){
                value1 = value1*value2;
            }
            else if (scanned.content[0] == '/'){
                value1 = value1/value2;
            }
            else if (scanned.content[0] == '^'){
                value1 = pow(value1,value2);
            }
            else if (scanned.content[0] == 'e'){
                value1 = value1*pow(10,value2);
            }
            output[outPos - 2].value = value1;
            outPos--;
        }
    }
    printf("%.3f\n",output[0].value);
    return 0;
}
int callOps ( struct inputSeperate * input , int length ) { int inPos , outPos = 0 ; struct inputSeperate output [ length ] ; struct inputSeperate scanned ; for ( inPos = 0 ; inPos < length ; inPos ++ ) { scanned = input [ inPos ] ; if ( scanned . isOperator == 0 ) { output [ outPos ] = scanned ; outPos ++ ; } else { double value1 = output [ outPos - 2 ] . value ; double value2 = output [ outPos - 1 ] . value ; if ( scanned . content [ 0 ] == ' ' ) { value1 = value1 + value2 ; } else if ( scanned . content [ 0 ] == ' ' ) { value1 = value1 - value2 ; } else if ( scanned . content [ 0 ] == ' ' ) { value1 = value1 * value2 ; } else if ( scanned . content [ 0 ] == ' ' ) { value1 = value1 / value2 ; } else if ( scanned . content [ 0 ] == ' ' ) { value1 = pow ( value1 , value2 ) ; } else if ( scanned . content [ 0 ] == ' ' ) { value1 = value1 * pow ( 10 , value2 ) ; } output [ outPos - 2 ] . value = value1 ; outPos -- ; } } printf ( " \n " , output [ 0 ] . value ) ; return 0 ; }
this function applies operations to the postfix expression and outputs a result
this function applies operations to the postfix expression and outputs a result
//loop through each struct in the postfix array //if the scanned value is a number, add it to the output. if its an  //operator, determine what the operator does and apply it to the values //already added to the output array //print the result to 3dp