Program to make Simple Calculator in C++.

It performs basic four mathematical operations (addition, subtraction, multiplication, and division) depending on the user’s choice, use the ‘switch’ case to identify the input operator to perform required calculation then display the result as shown here in the following program.

 

 

 
Step 1: Let’s open turboC++ and write the following Code:

 

//Code

 

#include<conio.h>

#include<iostream.h>

void main()

{

int d;

float a,b,c;

clrscr();

cout<<”enter first number:”;

cin>>a;

cout<<”enter second number:”;

cin>>b;

cout<<”\n Select any option : \n1.Add \n2.Subtract\n3.multiply\n4.Divide/n5.exit.

cin>>d;

switch(d)

{

case 1: c=a+b;

cout<<”rssult =”<<c;

break;

case 2: c=a-b;

cout<<”result=”<<c;

break;

case 3: c=a*b;

cout<<”result=”<<c;

break;

case 4: c=a/b;

cout<<”result=”<<c;

break;

default:

cout<<”invalid option choosen”;

break;

}

getch();

}

 

 

Step 2: Run the program and see output:

 

Output:

 

 

output

 

Happy coding.

Tags: , , ,