HOW TO MAKE a FOUR FUNCTIONAL CALCULATOR IN CPP

by sabarinath56 in Circuits > Computers

934 Views, 3 Favorites, 0 Comments

HOW TO MAKE a FOUR FUNCTIONAL CALCULATOR IN CPP

cpp-program-to-make-simple-calculator.jpg

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.

Open Your IDE

Screenshot (159).png

you can use any type of IDE

eg geny ,cfree ,visual studio etc ....

Save the Project With Extension ".cpp"

Screenshot (160).png

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 :{
 	
 }
}

Then Save the File Again by Press "ctrl+s"

Ctrl+S.png

To Run the Program Press "f5"

25-WMgnbPrbhSqFCiQr6gcnenbKW.jpg

Finally Enjoy the Working of the Code

Screenshot (162).png