Introduction: HOW TO MAKE a FOUR FUNCTIONAL CALCULATOR IN CPP
Calculators are used to everyone in daily life. A simple calculator can be made using a C++ program which is able to add, subtract, multiply and divide, two operands entered by the user. The if and goto statement is used to create a calculator.
Step 1: Open Your IDE
you can use any type of IDE
eg geny ,cfree ,visual studio etc ....
Step 2: Save the Project With Extension ".cpp"
Step 3: Copy the Code Given Below and Paste in the Compiler IDE
#include<iostream>
using namespace std;
int main()
{
char a;
float z;
goto r;
r :
{
system("cls");
cout<<"enter '+' for addition" << endl << "enter '-' for subtraction" << endl << "enter '*' for multiplication " << endl << "enter '/' for division "<<endl;
cin>> a;
if (a=='+')
{
float x,y;
cout<<"enter first number"<<endl;
cin >>x;
cout<<"enter second number"<<endl;
cin >>y;
z=x+y;
cout<<"sum of "<<x<<"+"<<y<<"="<<z<<endl;
}
else if (a=='-')
{
float x,y;
cout<<"enter first number"<<endl;
cin >>x;
cout<<"enter second number"<<endl;
cin >>y;
z=x-y;
cout<<"subtraction of "<<x<<"-"<<y<<"="<<z<<endl;
}
else if (a=='*')
{
float x,y;
cout<<"enter first number"<<endl;
cin >>x;
cout<<"enter second number"<<endl;
cin >>y;
z=x*y;
cout<<"multiplicative product of "<<x<<"*"<<y<<"="<<z<<endl;
}
else if (a=='/')
{
float x,y;
float z;
cout<<"enter first number"<<endl;
cin >>x;
cout<<"enter second number"<<endl;
cin >>y;
z=x/y;
cout<<"division of "<<x<<"/"<<y<<"="<<z<<endl;
}
else
{
cout << "unknown operation \n";
}
goto p;
}
p :
cout<< "to continue enter 'r' "<<endl<<"to close enter 'c'";
cin>>a;
if (a=='r')
{
goto r;
}
else if(a=='c')
{
goto e;
}
else
{
goto p;
}
e :{
}
}
