Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Change the code in the posted for the program posted in the same module named prog as follows and submit as program 6: Create functions

Change the code in the posted for the program posted in the same module named prog as follows and submit as program 6:

Create functions and function prototypes to replace each of the calculator actions. Prototype each function above main and write the function (definition) below main.

The input by the user and output statement of each calculation should stay in main and not be moved to a function except the output for function iseven which should be done in the function.

Each function will accept the value(s) supplied by the user as parameters and return the result in a return statement (not a printf statement except for iseven).

The result returned by each function should be outputted by a printf statement in main.

Create a function named display that contains: menu display statements, the user prompt to select an option, user input. This function should have no parameters and should return a character as the option chosen by the user.

The functions required are:

display(void); double add(double, double); double sub(double, double); double mult(double, double); double div(double, double); int remain(int, int); double square(double); double sqroot(double); int factorial(int); void iseven(int); int greaterint(double); int lesserint(double);

#include

#include

int main(void)

{

char menuoption;

int intx, inty, answeri, count, n, fact;

double doublex, doubley, answerd;

//prompt user

do{

//menu

printf(" Operation Menu Option ");

printf("Add A ");

printf("Subtract S ");

printf("Multiply M ");

printf("Divide D ");

printf("Remainder R ");

printf("Squared V ");

printf("Square Root T ");

printf("Factorial F ");

printf("Is even E ");

printf("Greater integer G ");

printf("Less integer L ");

printf("Exit program X ");

printf("Please enter a menu option from the table above: ");

scanf("%c", &menuoption);

switch (menuoption)

{

//addition

case'a': case'A':

printf("Please enter the first number: ");

scanf("%lf", &doublex);

printf("Please enter the second number: ");

scanf("%lf", &doubley);

answerd= doublex + doubley;

printf("Answer = %.2lf", answerd);

break;

//subtraction

case 's': case'S':

printf("Please enter the first number:");

scanf("%lf", &doublex);

printf("Please enter the second number:");

scanf("%lf", &doubley);

answerd= doublex-doubley;

printf("Answer = %.2lf", answerd);

break;

//multiplication

case 'm': case'M':

printf("Please enter the first number:");

scanf("%lf", &doublex);

printf("Please enter the second number:");

scanf("%lf", &doubley);

answerd= doublex * doubley;

printf("Answer = %.2f ", answerd);

break;

//division

case 'd': case'D':

printf("Please enter the first number:");

scanf("%lf", &doublex);

printf("Please enter the second number:");

scanf("%lf", &doubley);

if (doubley == 0) //checking if denominator is zero

printf("invalid, cannot divide by zero ");

else

{

answerd= doublex / doubley;

printf("Answer = %.2f ", answerd);

}

break;

//remainder

case 'r': case'R':

printf("Please enter the first number:");

scanf("%d", &intx);

printf("Please enter the second number:");

scanf("%d", &inty);

answeri= intx % inty;

printf("Answer = %d ", answeri);

break;

//squared

case 'v': case'V':

printf("Please enter the number to be squared:");

scanf("%lf", &doublex);

answerd= doublex*doublex;

printf("Answer = %.2lf", answerd);

break;

//square root

case 't': case'T':

printf("Please enter the number to take the square root of:");

scanf("%lf", &doublex);

if (doublex < 0) // checking is number for square root is negative

printf("invalid, cannot square root negative number ");

else

{

answerd= sqrt(doublex);

printf("Answer = %.2f ", answerd);

}

break;

//factorial

case 'f': case'F':

fact = 1;

printf("Please enter the number to take the factorial:");

scanf("%d", &n);

if (n<0)

printf("Cannot take the factorial of a negative number.");

else if (n>0)

{

for (count= n ; count>= 1; count--)

{

fact = fact * count;

}

printf("Factorial = %d", fact );

}

else

printf("The factorial of 0 is 1.");

break;

//even

case 'e': case'E':

printf("Please enter the first number:");

scanf("%d", &intx);

answeri= intx % 2;

if (answeri==0)

printf("The number is even. ");

else

printf("The number is not even. ");

break;

//greater integer

case 'g': case'G':

printf("Please enter the first number:");

scanf("%lf", &doublex);

answeri= ceil(doublex);

printf("Answer = %d", answeri);

break;

//lesser integer

case 'l': case'L':

printf("Please enter the first number:");

scanf("%d", &doublex);

answeri= floor(doublex) ;

printf("Answer = %d", answeri);

break;

//exit program

case 'x': case'X':

return 0;

break;

//improper input

default:

printf("Input not recognized. ");

}

} while (1);

return 0;

}

When writing the code in language c.Please do not use #include

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions

Question

How does codification help in standardisation? Explain.

Answered: 1 week ago

Question

2. Should a disciplinary system be established at Carter Cleaning?

Answered: 1 week ago

Question

1. What would you do if you were Jennifer, and why?

Answered: 1 week ago

Question

1. Explain what is meant by ethical behavior.

Answered: 1 week ago