Question: #include #include / / Function Declaration int getOption ( void ) ; void getData ( int * a , int * b ) ; float

#include
#include
// Function Declaration
int getOption(void);
void getData(int* a, int* b);
float calc(int option, int num1, int num2);
float add(float num1, float num2);
float sub(float num1, float num2);
float mul(float num1, float num2);
float divn(float num1, float num2);
void printResult(float num1, float num2,
float results, int option);
int main(void)
{
// Local Declarations
int done =0;
int option;
float num1;
float num2;
float result;
// Statments
while (!done)
{
option = getOption();
if (option ==5)
done =1;
else
{
do
{
printf("\
Enter two numbers: ");
scanf_s("%f %f", &num1, &num2);
if (option ==4 && num2==0)
{
printf("\a
*** Error ***");
printf("Second number cannot be 0
");
}// if
} while (option ==4 && num2==0);
switch (option)
{
case 1: result = add(num1,num2);
break;
case 2: result = sub(num1, num2);
break;
case 3: result = mul(num1, num2);
break;
case 4: result = divn(num1, num2);
}// switch
printResult(num1, num2, result, option);
}// else option !=5
}// while
printf("
Thank you for using Calculator.
");
return 0;
}// Main
/*============ getOption==============
This function shows a menu and reads the user options.
Pre nothing
Post returns a valid option
*/
int getOption(void)
{
// Local Decelaration
int option;
// Statment
do
{
printf("
*******************");
printf("
* Menu *");
printf("
**");
printf("
*1. ADD *");
printf("
*2. SUBTRACT *");
printf("
*3. MULTIPLY *");
printf("
*4. DIVIDE *");
printf("
*5. QUIT *");
printf("
**");
printf("
*******************");
printf("
Please type your choice ");
printf("and press the return key : ");
scanf_s("%d", &option);
if (option <1|| option >5)
printf("Invalid option. Please re-enter.
");
} while (option <1|| option >5);
return option;
}// get option

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!