Make calculator in c++(Mini Project)

C++ Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide Using switch...case

 

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

char op;

double n1,n2;

cout<<"Enter the Operator ( +, -, *, /)";

cin>>op;

cout<<"Enter two numbers";

cin>>n1>>n2;

switch(op)

{

case '+':

cout<<n1 << " + "<<n2<< " =" <<(n1+n2);

break;

case '-':

cout<<n1 << " - " <<n2 << "="<<(n1-n2);

break;

case '*':

cout<< n1 << " * " << n2 << "= " <<(n1*n2);

break;

case'/':

if( n2!=0.0)

cout<<n1<<" / "<<n2<< " = "<<(n1/n2);

else

cout<<"its divide by zero situation";

break;

default:

cout<<op <<" is an invalid operator";


}

getch();

}

Output:-



Post a Comment

0 Comments