C++ program to make simple calculator

#include <iostream>
using namespace std;

int main()
{
    int num1,num2,numStore,choice;
    cout<<"Enter first number : ";
    cin>>num1;
    cout<<"Enter second number : ";
    cin>>num2;
    cout<<"\t\tEnter 1 for addition\n";
    cout<<"\t\tEnter 2 for subtraction\n";
    cout<<"\t\tEnter 3 for multipication\n";
    cout<<"\t\tEnter 4 for Division\n";
    cout<<"Enter Your Choice : ";
    cin>>choice;
    switch(choice)
    {
    case 1:
      {
         numStore=num1+num2;
         cout<<"The sum of two numbers "<<num1<<" and "<<num2<<" is = "<<numStore;
         break;
      }
      case 2:
      {
         numStore=num1-num2;
         cout<<"The difference of two numbers "<<num1<<" and "<<num2<<" is = "<<numStore;
         break;
      }
      case 3:
      {
       numStore=num1*num2;
      cout<<"The product of two numbers "<<num1<<" and "<<num2<<" is = "<<numStore;
         break;
      }
      case 4:
      {
         if(num2==0)
         {
            cout<<"Division by Zero is not Possible";
            break;
         }

      numStore=num1/num2;
      cout<<"The result of division of two numbers "<<num1<<" and "<<num2<<" is = "<<numStore;
         break;
      }
    }
     cout << endl;
   return 0;
}

No comments:

Post a Comment