Basic Menu-Based Calculator in C

Here’s the code for a Basic Calculator Using Switch Statements:

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

int main(void)
{
int a, b;
int repeat=1;
printf(Welcome to the C calculator\nEnter any two numbers\n);
scanf(%d%d, &a, &b);

while(repeat==1)
{
int choice;
printf(Choose the operation to be performed\nDivision[1]\nMultiplication[2]\nAddition[3]\nSubtraction[4]\n);
scanf(%d, &choice);

int result;
switch(choice)
{
case 1:
result = a/b;
printf(The quotient is %d, result);
break;
case 2:
result = a*b;
printf(The product is %d, result);
break;
case 3:
result = a+b;
printf(The sum is %d, result);
break;
case 4:
result = a-b;
printf(The difference is %d, result);
break;
default:
printf(Please enter a valid choice);
break;
}
printf(\nRepeat[1]\nExit[0]n);
scanf(%d, &repeat);
}
getch();
}

Download the Application (.exe)


Also Check Out

Discuss - No Comments

No comments yet. Why not add one below?

Add a Comment

Your email address will not be published. Note marked required (*) fields.

Contact Durofy

For job openings, contact us at jobs@durofy.com | For any other info including business and advertising, contact us at dev@durofy.com

Durofy on Blackberry

Download the Durofy App to get updates on your Blackberry: To download, click here