Simple Calculator Using Switch Statement

#include "stdio.h"
#include "conio.h"
int main (void)
{
    int a,x,y;
    printf("Please enter 1 or 2 or 3 or 4 for addition, subtraction,multplication and division respectively:");
    scanf("%d", &a);
    switch(a)

    {
             case 1:
                  printf("please enter 2 numbers for addition\n");
                  scanf("%d %d", &x, &y);
                  printf("%d",x+y);
                  break;
             case 2:
                  printf("please enter 2 numbers for subtraction\n");
                  scanf("%d %d", &x, &y);
                  printf("%d",x-y);
                  break;
             case 3:
                  printf("please enter 2 numbers for substraction\n");
                  scanf("%d %d", &x, &y);
                  printf("%d",x*y);
                  break;
             case 4:
                  printf("please enter 2 numbers for substraction\n");
                  scanf("%d %d", &x, &y);
                  printf("%d",x/y);
             default:
                     printf("You do not enter 1 or 2 or 3 or 4\n");
                     break;
    }
    getch();
    return 0;
}
       

0 comments:

Post a Comment