Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem #3: Write an application that is a four function calculator<?xml:namespa

ID: 3531337 • Letter: P

Question

Problem #3:

Write an application that is a four function calculator<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

(+, -, * or x, / or )

printf("Enter number, operator, number );

scanf("%f %c %f",&num1, &op, &num2);

The I/O should look like this:

Enter number, operator, number

2 3

= 0.6667

Enter number, operator, number

5 x 5

= 25.00

You are to create four functions --

add, subtract, divide and multiply where each function returns the value calculated.

You are to pass pointers as the arguments and the expression in each function is to use pointers.

int add(int *num1, int *num2); the add function prototype

main.c

The main function is where you will write the I/O logic and call the requested functions. You are to choose the function to be performed by the operator entered. You are to continue to performing calculations until the user decides to exit the application.

Explanation / Answer

// please rate me its the correct code


#include<stdio.h>

int add(int *num1, int *num2);

int subtract(int *num1, int *num2);

int divide(int *num1, int *num2);

int multiply(int *num1, int *num2);

int main()

{

int num1, num2,result,;

char ch=y,operator;

do{

printf(" Enter the operations :");

scanf("%d %c %d",&num1,&operator,&num2);


switch(operator) {

case '+' :

result=add(&num1, &num2);

printf(" = %d ,result);

break;

case '-' :

result=subtract(&num1, &num2);

printf(" = %d ,result);

break;

case '*' :

result=multiply(&num1, &num2);

printf(" = %d ,result);

break;

case '/' :

if(num2!=0)

result=divide(&num1, &num2);

else{

printf(" Second operand can't be zero ");

break ;

}

printf(" = %d ,result);

break;

default :

printf("Error in choice of operator");

}

printf("To continue Press 'y' else 'N'");

scanf("%c",&ch);

}while(ch !='n'||ch!='N');

return 0;

}

int add(int *num1, int *num2){

return (*num1+ *num2) ;

}

int subtract(int *num1, int *num2){

return (*num1 -*num2) ;

}

int divide(int *num1, int *num2){

return (*num1 / *num2) ;

}

int multiply(int *num1, int *num2){

return (*num1 * *num2) ;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote