Answer to Question #332997 in C for Justin

Question #332997

Make a program that allows the user to select the operation he or she wishes to perform. Furthermore, your program will keep asking the user to pick until he or she selects exit to stop the execution.

1
Expert's answer
2022-04-24T17:16:44-0400



#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
void MenuAdd()
{
  printf("Input two numbers for add\n");
  int a;
  int b;
  scanf("%i",&a);
  scanf("%i",&b);
  printf("%i+%i=%i\n",a,b,a+b);
}
void MenuSub()
{
  printf("Input two numbers for sub\n");
  int a;
  int b;
  scanf("%i",&a);
  scanf("%i",&b);
  printf("%i-%i=%i\n",a,b,a-b);
}
void MenuSqrt()
{
  double d;
  printf("Input a numbers:");
  scanf("%lf",&d);
  printf("%0.4lf",sqrt(d));
}


int main(void) {
  printf("--- --------- Welcome to mu Calc ------ --------\n");
  int quit=0;
  while(!quit)
    {
      printf("1 -Add two numbers\n");
      printf("2 -Subtract two numbers\n");
      printf("3 -sqrt\n");
      int cmd;
      scanf("%i",&cmd);
      switch(cmd)
        {
          case 1:
            {
              MenuAdd();
              break;
            }
          case 2:
            {
              MenuSub();
              break;
            }
          case 3:
            {
              MenuSqrt();
              break;
            }
        }
      char ch;
      printf("\nquit/continue (q/c):\n");
      scanf(" %c",&ch);
      if(ch=='q')
        quit=1;
    }
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS