Menu Driven Calculator in C

Write a program in C to create Menu Driven Calculator 


#include <stdio.h>
#include <conio.h>

void main()
{
            int a,b,c,ch;
            clrscr();
            printf(“\n1.add\n2.subtract\n3.multiply\n4.division\n5.remainder\n);
            printf(“\nenter your choice\n”);
            scanf(“%d”,&ch);
            switch(ch)
            {
                        case1:
                                    printf(“\nenter values of a and b\n”);
                                    scanf(“%d%d”,&a,&b);
                                    c=a+b;
                                    printf(“\nthe answer is %d”,c);
                        break;
                        case2:
                                    printf(“\nenter values of a and b\n”);
                                    scanf(“%d%d”,&a,&b);
                                    c=a-b;
                                    printf(“\nthe answer is %d”,c);
                        break;
                        case3:
                                    printf(“\nenter values of a and b\n”);
                                    scanf(“%d%d”,&a,&b);
                                    c=a*b;
                                    printf(“\nthe answer is %d”,c);
                        break;
                        case4:
                                    printf(“\nenter values of a and b\n”);
                                    scanf(“%d%d”,&a,&b);
                                    c=a/b;
                                    printf(“\nthe answer is %d”,c);
                        break;
                        case5:
                                    printf(“\nenter values of a and b\n”);
                                    scanf(“%d%d”,&a,&b);
                                    c=a%b;
                                    printf(“\nthe answer is %d”,c);
                        break;
                        default:
                                    printf(“\nenter the correct choice”);
                        break;
            }
            getch();
}


Post a Comment