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

Write a C program to implement a four function calculator. The program should pr

ID: 3789273 • Letter: W

Question

Write a C program to implement a four function calculator. The program should prompt the user for a formula. After the user enters a formula, consisting of two floating point values separated by an operator, the program calculates the value of the formula and prints out that result. Operators supported by the calculator are addition (denoted by +), subtraction (denoted by -), multiplication (denoted by *), and division (denoted by /). After the program calculates and prints the result, it should prompt the user to continue with another formula or terminate the program.

Explanation / Answer

#include <stdio.h>
void main()
{
char op;
float opr1, opr2, res;

printf("simple Calculator ");
printf("_______________ ");
printf("Enter 2 numbers ");
scanf("%f %f", &opr1, &opr2);
fflush(stdin);
printf("Enter the operator [+,-,*,/] ");
scanf("%s", &op);

do{
switch(op)
{
case '+': res = opr1 + opr2;
break;
case '-': res = opr1 - opr2;
break;
case '*': res= opr1 * opr2;
break;
case '/': res = opr1 / opr2;
break;
default : printf("Please enter correct input");
break;
}

}while(op!=' ');
printf(" %5.2f %c %5.2f = %5.2f ", opr1, op, opr2, res);
}

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