Tuesday, 7 April 2015

Write a program in C++ for Simulation of a Simple Calculator using Switch Case.

:- Write a program in C++ for Simulation of a Simple calculator using Switch Case .


#include<iostream.h>

void main()
{
  int a,b;
  char o;
  cout<<"\n enter the two operands: ";
  cin>>a>>b;

  cout<<"\n enter the operator (+,-,*,/)";
  cin>>o;

  switch(o)
  {
case '+': cout<<endl<<a<<'+'<<b<<"  =  "<<a+b;
break;
case '-': cout<<endl<<a<<'-'<<b<<"  =  "<<a-b;
break;
case '*': cout<<endl<<a<<'*'<<b<<"  =  "<<a*b;
break;
case '/': cout<<endl<<a<<'/'<<b<<"  =  "<<a/b;
break;
default : cout<<"\n wrong choice";


  }

}

The Output of this Program:-


No comments:

Post a Comment