THis almost works, but i'm stuck. It terminates, I want it after the user does a problem, returns to the top list.
Code:#include <ctype.h> #include <stdio.h> #include <math.h> int main() { float addition, add1, add2, add3; float subtract, sub1, sub2; float multiply, mult1, mult2, mult3; float division, div1, div2; float modulate, smod1, smod2; char E, choice; do { printf("Please type in one of the following letters:"); printf("\nA to add three numbers: "); printf("\nS to Subtract two numbers: "); printf("\nM to Multiply three number: "); printf("\nD to Divide two number: "); printf("\nO to Modulate two number: "); printf("\nE to Exit program: "); printf("\n>:\n"); scanf("%c", &choice); fflush(0); choice=toupper(choice); }while (choice != 'A' && choice != 'S' && choice != 'M' && choice != 'D' && choice != 'O' && choice != 'E'); switch (choice) { case 'A': printf("\nPlease type the first number: "); scanf("%f", &add1); printf("\nPlease type the second number: "); scanf("%f", &add2); printf("\nPlease type the third number: "); scanf("%f", &add3); addition = add1+add2+add3; printf("%.2f + %.2f + %.2f equals %.2f\n", add1, add2, add3, addition); break; case 'S': printf("\nPlease type the first number: "); scanf("%f", &sub1); printf("\nPlease type the second number: "); scanf("%f", &sub2); subtract = sub1-sub2; printf("%.2f minus %.2f equals %.2f\n", sub1, sub2, subtract); break; case 'M': printf("\nPlease type the first number: "); scanf("%f", &mult1); printf("\nPlease type the second number: "); scanf("%f", &mult2); printf("\nPlease type the third number: "); scanf("%f", &mult3); multiply = mult1*mult2*mult3; printf("%.2f x %.2f x %.2f = %.2f\n", mult1, mult2, mult3, multiply); break; case 'D': printf("\nPlease type the first number: "); scanf("%f", &div1); printf("\nPlease type the second number: "); scanf("%f", &div2); division = div1/div2; printf("%.2f divided by %.2f equals %.2f\n\n", div1, div2, division); break; case 'O': printf("\nPlease type the first number: "); scanf("%f", &smod1); printf("\nPlease type the second number: "); scanf("%f", &smod2); modulate = fmod(smod1, smod2); printf("The modulus of %.2f and %.2f leaves a remainder of %.2f\n\n", smod1, smod2, modulate); break; case 'E': printf("\n\nThank You and Goodbye!: %c", E); scanf("%c", &E); break; default: printf("\nInvalid choice, please try again"); fflush(0); choice=toupper(choice); } return 0; }
PS: This is the format we have to use that our instructer told us.



LinkBack URL
About LinkBacks


