/////////////////////////////////// // // program_3 project // // created 8/12/21 by tj // rev 0 // /////////////////////////////////// // // Program to provide various calculations w/ functions // // Reads in a values for val1 and val2 // Reads in the desired operation // Provides the result // // inputs: 2 values for val1 and val2, a character for the operation // outputs: prints result of val1 operation val2 // /////////////////////////////////// #include "mbed.h" #include // only needed when printing // function prototypes float get_val(char side); char get_op(void); void calc_print_results(float val_l, float val_r, char oper); int main(void){ setbuf(stdout, NULL); // disable buffering when printing // splash printf("\n\nprogram_3\n"); printf("Using Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); printf("Welcome to my calculator program (using functions)\n\n"); float val1; float val2; char operation; // infinte loop while(1){ // ask for and read in values and operation val1 = get_val('L'); val2 = get_val('R'); operation = get_op(); calc_print_results(val1, val2, operation); }// end while return 0; }// end main float get_val(char side){ float val; // ask for and read in value printf("Please enter a value for %c side of the operation ", side); scanf("%f", &val); return val; }// end get_val char get_op(void){ char op; printf("Please enter the operation requested \(+ - * /): "); scanf(" %c", &op); return op; }// end get_op void calc_print_results(float val_l, float val_r, char oper){ float result; // select the calculation and execute switch(oper){ case '+': result = val_l + val_r; printf("%f %c %f = %f\n\n", val_l, oper, val_r, result); break; case '-': result = val_l - val_r; printf("%f %c %f = %f\n\n", val_l, oper, val_r, result); break; case '*': result = val_l * val_r; printf("%f %c %f = %f\n\n", val_l, oper, val_r, result); break; case '/': result = val_l / val_r; printf("%f %c %f = %f\n\n", val_l, oper, val_r, result); break; default: printf("invalid operation\n\n"); break; } // end switch return; }// end calc_print_results