Write a C program that displays the following menu on the screen:
   MENU OF OPERATIONS
  By: <Your Name Here>
  [ 1 ] - Addition
  [ 2 ] - Subtraction
  [ 3 ] - Multiplication
  [ 4 ] - Division
  [ 5 ] - Modulo Division
  [ 6 ] - Quit
  Enter Your Choice:  3
  You have chosen Multiplication!
  Enter three integers: 89 78 67
  Sum = 465,114
  Thank you for using my program...
The user has to be prompted to input a number of his/her preferred operation and will then be asked to enter three integers and display the computed value based on the inputted operation.Â
#include <stdio.h>
#include <stdlib.h>
int main()
{
int ch=-1;
int number1;
int number2;
int number3;
int sum;
int difference;
int product;
double div;
int modulo;
while(ch!=6){
printf("MENU OF OPERATIONS\n");
printf("By: <Your Name Here>\n");
printf("[ 1 ] - Addition\n");
printf("[ 2 ] - Subtraction\n");
printf("[ 3 ] - Multiplication\n");
printf("[ 4 ] - Division\n");
printf("[ 5 ] - Modulo Division\n");
printf("[ 6 ] - Quit\n");
printf("Enter Your Choice: ");
scanf("%d",&ch);
if(ch==1){
printf("You have chosen Addition!\n");
printf("Enter three integers: ");
scanf("%d %d %d",&number1,&number2,&number3);
sum=number1+number2+number3;
printf("Sum = %d\n\n",sum);
}else if(ch==2){
printf("You have chosen Subtraction!\n");
printf("Enter three integers: ");
scanf("%d %d %d",&number1,&number2,&number3);
difference=number1-number2-number3;
printf("Difference = %d\n\n",difference);
}else if(ch==3){
printf("You have chosen Multiplication!\n");
printf("Enter three integers: ");
scanf("%d %d %d",&number1,&number2,&number3);
product=number1*number2*number3;
printf("Product = %d\n\n",product);
}else if(ch==4){
printf("You have chosen Division!\n");
printf("Enter three integers: ");
scanf("%d %d %d",&number1,&number2,&number3);
div=(double)number1/(double)number2/(double)number3;
printf("Division = %.3f\n\n",div);
}else if(ch==5){
printf("You have chosen Modulo Division!\n");
printf("Enter three integers: ");
scanf("%d %d %d",&number1,&number2,&number3);
modulo=number1%number2%number3;
printf("Modulo Division = %d\n\n",modulo);
}else if(ch==6){
}else{
printf("Wrong menu item.\n\n");
}
}
printf("\nThank you for using my program...\n");
getchar();
return 0;
}
Comments
Leave a comment