Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

calculator in cpp

#include <iostream>
using namespace std;
// Hi I'm Jillani Soft Tech. I'm a Developer.
main()
{
	while(true)
	{
		
		
		int sum,mul,sub,div;	// variable decalration
		int num1,num2;
		int choice;
		
		cout<<"

			----------Main Menu-----------"<<endl;
		
		cout<<"Press 1 for Sum "<<endl;
		cout<<"Press 2 for Sub "<<endl;
		cout<<"Press 3 for Mul "<<endl;
		cout<<"Press 4 for Div "<<endl;
		
		cout<<"
Enter Your Choice ? "<<endl;	
		cin>>choice;
		
		
		cout<<"Enter frist number : "<<endl;
		cin>>num1;
		cout<<"Enter Second number : "<<endl;
		cin>>num2;
		
		
		
		if(choice==1)
		{
			sum=num1+num2;
			cout<<"There sum is this : "<<sum<<endl;
		}
		else if(choice==2)
		{
			sub=num1-num2;
			cout<<"There sub is this : "<<sub<<endl;
		}
		else if(choice==3)
		{
			mul=num1*num2;
			cout<<"There mul is this : "<<mul<<endl;
		}
		else if(choice==4)
		{
			div=num1/num2;
			cout<<"There div is this : "<<div<<endl;
		}
		else
		{
			
			cout<<"

			Invalid Selection Try Again.... "<<endl;
		}
		
	}
}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #calculator #cpp
ADD COMMENT
Topic
Name
4+6 =