/////////////////////////////////// // // program_2 project // // created 8/12/21 by tj // rev 0 // /////////////////////////////////// // // Program to provide various calculations // // 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 int main(void){ setbuf(stdout, NULL); // disable buffering when printing // splash printf("\n\nprogram_2\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\n\n"); float val1; float val2; char operation; float result; // infinite loop while(1){ // ask for and read in values and operation printf("Please enter a value for left side of the operation "); scanf("%f", &val1); printf("Please enter a value for right side of the operation "); scanf("%f", &val2); printf("Please enter the operation requested \(+ - * /): "); scanf(" %c", &operation); // select the calculation and execute switch(operation){ case '+': result = val1 + val2; printf("%f %c %f = %f\n\n", val1, operation, val2, result); break; case '-': result = val1 - val2; printf("%f %c %f = %f\n\n", val1, operation, val2, result); break; case '*': result = val1 * val2; printf("%f %c %f = %f\n\n", val1, operation, val2, result); break; case '/': result = val1 / val2; printf("%f %c %f = %f\n\n", val1, operation, val2, result); break; default: printf("invalid operation\n\n"); break; } // end switch }// end while return 0; }// end main