The question says Write a menu driven program that finds the minimum, maximum and sum of 3 numbers (integers). All the numbers entered should be unique. (i.e. no two numbers should be same .Check this condition)
Please adhere to the following guidelines.
a. Write a function that finds the smallest of the numbers.
b. Write a function that finds the largest of the numbers.
c. Write a function to display the following menu.
d. Write a function to display the following menu.
****************
* *
* Please select one of the following :- *
* *
* 1. Sum of the numbers *
* 2. Smallest of numbers *
* 3. Largest of numbers *
* 4. Exit *
* Enter your choice (1-4) *
*****************
The program should use the function to display the above menu. Then, the function should execute based on the selection made by the user. After a function is executed, the menu should appear again (there by allowing the user to perform another action). The program only terminates if 4 is entered.
I did the following in Borland c++:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int calculate_sum(int,int,int);
int calculate_maximum(int,int,int);
int calculate_minimum(int,int,int);
void print_results(int,int,int)
void main()
{
char request[20];
char menu[9];
int num1,num2,num3,sum,min,max;
int choice;
do
{
printf("Please enter the word \"menu\" to see the desired request that can be made in this program\n");
scanf("%s",request);
strcpy(menu,request);
// prompting user to input the word menu so that they can see the menu in the calling function
if (menu == 'menu')
{
void print_menu()
else
printf("\nPlease re-enter request\n");
scanf("%s",request);
}
// inputing the choice either 1,2 or 3 from the menu printed above from the calling function.
scanf("%s",choice);
// testing for the number 1,2 or three entered by user,any one can allow the program to run.
if(((choice=='1')||(choice=='2')||(choice=='3')))
{
printf("\n Please enter number 1\n");
scanf("%d",&num1);
printf("\n Please enter number 2\n")
scanf("%d",&num2);
printf("\n Please enter number 3\n");
scanf("%d",&num3);
while ((((((num1==num2)||(num1==num3)||(num2==num1)||num2==num3)||(num3==num1)||num3==num2))))))
{
printf("\n Please re-enter three unique,no two numbers can be the same \n");
scanf("%d%d%d",&num1,&num2,&num3);
}
printf("\n");
printf("THANK YOU FOR SUCCESFULLY ENTERING THE PROGRAM!!!\n");
printf("\n");
// testing to see what choice was entered by user above
if(choice=='1')
{
sum= calculate_sum(num1,num2,num3);
}
else if(choice=='2')
{
max= calculate_max(num1,num2,num3);
}
else if(choice=='3')
{
min= calculate_min(num1,num2,num3);
}
// printing results after calculation takes place.
print_results(sum,max,min);
else
// a number other than 1,2 or 3 was entered so program exits
exit(0);
}
}
}
while (((choice!=1)||(choice!=2)||(choice!=3)))
printf("You entered a value other than the values shown, ***Good Bye***\n");
}
getchar();
getchar();
// Calling function for sum of numbers
int calculate_sum(int n1,int n2, int n3)
{
int sum_of_numbers;
sum_of_numbers= (n1+n2+n3);
return sum_of_numbers;
}
// Calling funtion for maximum and minimum number
int calculate_maximum(int n1,int n2, int n3)
{
int max;
max=n1;
if(n2>max)
{
max=n2;
}
else if(n3>max)
max=n3;
return max;
}
int calculate_minimum(int n1,int n2, int n3)
{
int min;
min=n1;
if(n2<min)
{
min=n2;
}
else if(n3<min)
min=n3;
return min;
}
void print_values(sum_of_numbers,max,min)
{
printf("Sum of numbers is:\t %d\n",sum_of_numbers);
printf("Maximum number is:\t %d\n",max);
printf("Minimum number is:\t %d\n",min);
}
void print_menu()
{
printf("\n***************\n");
printf("\n");
printf("* *\n");
printf("\n Please select one of the following:-\n");
printf("\n* *\n");
printf("\n* 1. Sum of the Numbers *\n");
printf("\n* 2. Smallest of Numbers *\n");
printf("\n* 3. Largest of Numbers *\n");
printf("\n* 4. Exit *\n");
printf("\n* Enter your Choice(1-4): *\n");
}