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

In this assignment, you will create a text-based, menu-driven calculator program

ID: 1809526 • Letter: I

Question

In this assignment, you will create a text-based, menu-driven calculator program. Allow the user to choose whether to add, subtract, multiply, or divide two numbers. The program should input two numbers from the user, perform the appropriate calculation, and display the result. Use an array of function pointers in which each pointer represents a function that returns void and receives two double parameters. The corresponding functions should each display messages indicating which calculation was performed, the value of the parameters, and the result of the calculation.

Explanation / Answer

main()
{
int a,b,ch;
float result;
do
{
clrscr();
printf("select the operation from list");
printf(" 1.ADDITION 2.SUBSTRACTION");
printf(" 3.MULTIPLICATION 4.DIVISION");
printf(" Enter your choice:");
scanf("%d",&ch);
}
while((ch>4)||(ch<1));
switch(ch)
{
case1: printf(" enter two numbers:");
scanf("%d%d",&a,&b);
result=a+b;
printf(" result=%f",result);
break;
case2: printf(" enter two numbers:");
scanf("%d%d",&a,&b);
result=a-b;
printf(" result=%f",result);
break;
case3: printf(" enter two numbers:");
scanf("%d%d",&a,&b);
result=a*b;
printf(" result=%f",result);
break;
case4: printf(" enter two numbers:");
scanf("%d%d",&a,&b);
result=a/b;
printf(" result=%f",result);
break;
}
getch();
}