C++ Program for Mini Calculator [DEVCPP/GCC]

PROGRAM

//A simple program for Mini Calculator using do-while loop and conditional statements.

# include <iostream>

using namespace std;

int main()
{
int op1,op2,res=0;
char ch,con;

do
{

cout<<"\nENTER TWO NUMBERS:\n";
cin>>op1>>op2;

cout<<"ENTER OPERATOR(+,-,*,/,%):\n";
cin>>ch;

switch(ch)
{
case '+':
res=op1+op2;
break;

case '-':
res=op1-op2;
break;

case '*':
res=op1*op2;
break;

case '/':
 
                           if(!op2)                // True when op2 is zero
cout<<"DIVIDE BY ZERO ERROR!!!\n";
else
res=op1/op2;
 
  break;

case '%':
 
                           if(!op2)               // True when op2 is zero
cout<<"DIVIDE BY ZERO ERROR!!!\n";
else
{
                                  int q,r;
q=op1/op2;
r=op1-(op2*q);
res=r;
}

break;

default :
cout<<"WRONG OPERATOR\n";
}

cout<<"THE CALCULATED RESULT IS:"<<res<<"\n\n";

cout<<"DO YOU WISH TO CONTINUE:";
cin>>con;
 
}while(con=='Y'|| con=='y');

return 0;
}

OUTPUT

C++ Program for Mini Calculator with output

Share this

Related Posts

1 comments :

comments
May 31, 2016 at 1:33 PM delete

Thanks for your generous response! Do subscribe to our blog and allow us to serve better.

Reply
avatar

FIND US ON FACEBOOK!