# Code for simple calculator in 'C'

Discussion in 'Meet and Greet' started by cprogram, Oct 15, 2011.

1. ### cprogramNew Member

Joined:
Oct 14, 2011
Messages:
2
0
Trophy Points:
0
Occupation:
STUDENT
Location:
INDIA
Code:
```#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
clrscr();
char ch;
int m,n;
do
{
do
{
//ch='1';
printf("\n2 - SUBTRACTION");
printf("\n3 - MULTIPLITION");
printf("\n4 - DIVISION");
printf("\n5 - REMAINDER");
printf("\n6 - EXIT");
ch=getch();
clrscr();

if(ch!='1' || ch!='2'|| ch!='3' || ch!='4' || ch!='5' || ch!='6')
{
gotoxy(1,1);
textbackground(RED);
}
textbackground(BLACK);

if(ch=='6')
exit(0);
}while(ch!='1' && ch!='2' && ch!='3' && ch!='4' && ch!='5' && ch!='6');
clrscr();
printf("\nENTER FIRST NUMBER ");
scanf("%d",&m);
printf("\nENTER SECOND NUMBER ");
scanf("%d",&n);

switch(ch)
{
case '1':
printf("\n %d + %d = %d ",m,n,m+n);
break;
case '2':
printf("\n %d - %d = %d ",m,n,m-n);
break;
case '3':
printf("\n %d X %d = %d ",m,n,m*n);
break;
case '4':
printf("\n %d / %d = %d ",m,n,m/n);
break;
case '5':
printf("\n %d %% %d = %d ",m,n,m%n);
break;
}

printf("\n\n\tDO YOU WANT TO AGAIN USE CALCULATOR (Y/N)");
ch=getch();
clrscr();
}while(ch=='y' || ch=='Y');
printf("\n\nPRESS ANY KEY TO EXIT");
getch();
}```