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.
#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;
}
Comments
Leave a comment