/***********************************************************************\ * Name: Program3 * * Purpose: Allow user to perform basic mathematical operations * * Date: 04-12-06 * * Author: Katharina van Santen * \***********************************************************************/ #include //include the stdio library double add(double,double ); //declare a user defined library of add double subtract(double,double ); //declare a user defined library of subtract double multiply(double,double ); //declare a user defined library of multiply double divide(double,double ); //declare a user defined library of divide void main (void) //declare the main function { //start the main function int choice; double x, y; double returned_sum; double returned_difference; double returned_product; double returned_quotient; printf("What would you like to do?\nPlease choose a number:\n"); printf("1.\tAdd\n2.\tSubtract\n3.\tMultiply\n4.\tDivide\n5.\tEnd Program\n"); scanf("%d", &choice); if (choice==1||choice==2||choice==3||choice==4) { printf("Please enter two numbers of type double\t"); scanf("%lf%lf",&x,&y); } while (choice!=5) { if (choice==1) { add(x,y); returned_sum=add(x,y); printf("The sum of your two numbers %lf and %lf is %lf\n",x,y,returned_sum); } else if (choice==2) { subtract(x,y); returned_difference=subtract(x,y); printf("The difference of your two numbers %lf and %lf is %lf\n",x,y,returned_difference); } else if (choice==3) { multiply(x,y); returned_product=multiply(x,y); printf("The product of your two numbers %lf and %lf is %lf\n",x,y,returned_product); } else if (choice==4) { if (y!=0) { divide(x,y); returned_quotient=divide(x,y); printf("The quotient of your two numbers %lf and %lf is %lf\n",x,y,returned_quotient); } else printf("You cannot divide by 0!"); } } } //end the main function double add(double x,double y) { //start the add function double sum; sum=x+y; return sum; } //end the add function double subtract(double x,double y) { //start the subtract function double difference; difference=x-y; return difference; } //end the subtract function double multiply(double x,double y) { //start the multiply function double product; product=x*y; return product; } //end the multiply function double divide(double x,double y) { //start the divide function double quotient; quotient=x/y; return quotient; } //end the divde function