make calculator in C language


#include

void ssc();
void sci();

void main()
{
//declaration
int num1,num2;
char ope[4];

//clearing the screen
clrscr();

//printing welcome message
printf("\t\t\t\t***CALCULATOR***\n\tFor help: type help\n");

start:

cin>>ope;
if(strcmp(ope,"end")==0) goto end;
else if(strcmp(ope,"help")==0)
{
printf("\n\nTo do calculations you must first know the keyword for the specific calculation\nfor,\n\taddition - add\n\tsubtraction - sub\n\tdivision - div\n\tmultiplication - mul\n\treminder - rem\n\tclose calculator - end\n\tTo switch to scientific calculator mode - sci\tIn scientific calculator mode you can get sin,cos,tan and log values.\n\tsuccessive calculating mode - ssc\n\tYou must specify the keyword and the two numbers separated by space\n");
goto start;
}
else if(strcmp(ope,"sci")==0)
{
sci();
goto start;
}
else if(strcmp(ope,"ssc")==0)
{
ssc();
goto start;
}
else if(strcmp(ope,"clr")==0)
{
clrscr();
cout<<"\t\t\t\t***CALCULATOR***\n";
goto start;
}

cin>>num1>>num2;
if(strcmp(ope,"add")==0) printf("The sum of %d and %d is %d\n",num1,num2,num1+num2);
else if(strcmp(ope,"sub")==0) printf("The difference between %d and %d is %d\n",num1,num2,num1-num2);
else if(strcmp(ope,"mul")==0) printf("The product of %d and %d is %d\n",num1,num2,num1*num2);
else if(strcmp(ope,"div")==0) printf("The qoutient on dividing %d by %d is %d\n",num1,num2,num1/num2);
else if(strcmp(ope,"rem")==0) printf("The reminder on divindin %d by %d is %d\n",num1,num2,num1%num2);
else printf("Invalid command only keywords available are add,sub,mul,div,rem.\n");
goto start;
end:
}
void sci()
{
//declaration
char ope[3];
int num1;

start:

cin>>ope;
if(strcmp(ope,"end")==0) goto end;
cin>>num1;
if(strcmp(ope,"sin")==0) printf("The sin value of %d is %d\n",num1,sin(num1));
else if(strcmp(ope,"cos")==0) printf("The cos value of %d is %d\n",num1,cos(num1));
else if(strcmp(ope,"tan")==0) printf("The tangent value of %d is %d\n",num1,tan(num1));
else if(strcmp(ope,"log")==0) printf("The log value of %d is %d\n",num1,log(num1));
else printf("Invalid command only keywords available are sin,cos,tan and log.\n");
goto start;
end:
cout<<"You are now leaving the scientific calculator. To return to scientific calculator mode type sci.\n";
}

void ssc()
{
//declaration
char ope[3];
int result,num1;

cout<<"Enter the first value:";
cin>>result;

start:

cin>>ope;
if(strcmp(ope,"end")==0) goto end;
cin>>num1;
if(strcmp(ope,"add")==0) result=result+num1;
else if(strcmp(ope,"sub")==0) result=result-num1;
else if(strcmp(ope,"div")==0) result=result/num1;
else if(strcmp(ope,"mul")==0) result=result*num1;
else printf("Invalid command only available keywords are add,sub,mul,div\n");
printf("For now the result is %d\n",result);
goto start;
end:
cout<<"Now you exiting the succesive calculating mode\n";
}

Translate

 

Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com