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

EEL4834 Program 3 Create a simple scientific calculator program as follows: 1- D

ID: 3872295 • Letter: E

Question

EEL4834 Program 3 Create a simple scientific calculator program as follows: 1- Display a menu of options according to table. 2- Ask the user to enter a menu option (upper and lower case will work). 3- If menu option is not valid, display msg "invalid option" and repeat parts 1 and 2. (use do-while) 4- For "add" option ask the user to enter two numbers, store as double and display sum. 5- For subtract option ask the user to enter two numbers, store as double and display difference. 6- For multiply option, same as above. 7- For divide option, same as above(test the denominator, if zero, display an appropriate msg). 8- For remainder option, ask the user to enter two integers and displays remainder 9- For squared, ask the user to input a number and output the square of the number. 10- For square root, check if the number is negative and output appropriate msg. 11- For factorial, ask for a number an output factorial ( 5! = 5*4*3*2*1). (use for loop) 12- For is even, display msg indicating if number is even. 13- For greater integer, round the number to an integer greater than number. 14- For less integer, round the number to an integer less than number. Every time a calculation ends, the menu is re-displayed. The program will only exit when the user enters X. Variables Double . double Double , double Double double Menu option Operation Add subtract multiply divide Sample input 5.6,3 5.6,3 10 , 4 10, 4 Sample output 8.60 2.60 40.00 2.50 Double , double remainder Integer, integer double double 4.00 3.00 120 ls even Square root factorial 9.0 int s even Greater integer Less integer Exit progranm teger integer double double 3.2 3.2

Explanation / Answer

The program is written is C.

To compile use command $ gcc filename.c -lm   

because header file named math.h is used.

to execute use command $ ./a.out

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
char ch ;
double a,b,res;
int x,y ,ans,choice;
do
{
printf(" A.Add S.Substract M.Multiply D.Divide R.Remainder V.Square T.SquraeROot F.factorial E.Even G.Greater Integer L.Less Intger X.Exit Program these are the choices Enter one choice ");
scanf("%c",&ch);
switch(ch)
{
case 'A':
case 'a':
printf("Enter two double values ");
scanf("%lf%lf",&a,&b);
res=a+b;
printf("Result is %lf ",res);
break;
case 'S':
case 's':
printf("Enter two double values ");
scanf("%lf%lf",&a,&b);
res=a-b;
printf("Result is %lf ",res);
break;
case 'M':
case 'm':
printf("Enter two double values ");
scanf("%lf%lf",&a,&b);
res=a*b;
printf("Result is %lf ",res);
break;
case 'D':
case 'd':
printf("Enter two double values ");
scanf("%lf%lf",&a,&b);
res=a/b;
printf("Result is %lf ",res);
break;
case 'R':
case 'r':
printf("Enter two intger values ");
scanf("%d%d",&x,&y);
ans=x%y;
printf("Result is %d ",ans);
break;
case 'V':
case 'v':
printf("Enter a double value ");
scanf("%lf",&a);
res=a*a;
printf("Result is %lf ",res);
break;
case 'T':
case 't':
printf("Enter a double value ");
scanf("%lf",&a);
res=sqrt(a);//defined in math.h
printf("Result is %lf ",res);
break;
case 'F':
case 'f':
printf("Enter an integer values ");
scanf("%d",&x);
ans=1;
while(x>1)
{
ans=ans*x;
x--;
}
printf("Result is %d ",ans);
break;
case 'E':
case 'e':
printf("Enter an integer values ");
scanf("%d",&x);
ans=x%2;
if(ans==0)
{
printf("Even ");
}
else
{
printf("Not Even ");
}
break;
case 'G':
case 'g':
printf("Enter a double value ");
scanf("%lf",&a);
ans=(int)a+1;
printf("Result is %d ",ans);
break;
case 'L':
case 'l':
printf("Enter a double value ");
scanf("%lf",&a);
ans=(int)a;
printf("Result is %d ",ans);
break;
case 'X':
case 'x':
exit(0);
default : printf("Enter a valid choice ");
}
printf("Do you want to continue ? Enter 1 to continue else 0 to exit ");
scanf("%d",&choice);
}while(choice!=0);
return 0;
}