How to Make Calculator in C++


Here we can learn how to make the Calculator by using switch case.


#include<iostream.h>
#include<conio.h>

void main()
{ clrscr();
  int choice;

   cout<<endl
    <<"1-ADDITION\n"
    <<"2-SUBTRACTIO\n"
    <<"3-MULTIPLICATION\n"
    <<"4-DIVISION\n";

   cout<<"Enter number between(1-9)";
   cin>>choice;

  switch(choice)
  {
    int x,y,add,sub,multi,divide;
    case 1:cout<<"Add\n";
   cout<<"Enter number1\n";
   cin>>x;
   cout<<"Enter number2\n";
   cin>>y;
   add=x+y;
   cout<<"Addition of 2 numbers\t"<<add;
   break;

    case 2: cout<<"Sub\n";
    cout<<"Enter number1\n";
    cin>>x;
    cout<<"Enter number2\n";
    cin>>y;
    sub=x-y;
    cout<<"Subtraction of 2 numbers\t"<<sub;

   break;
    case 3: cout<<"Multiply\n";
    cout<<"Enter number1\n";
    cin>>x;
    cout<<"Enter number2\n";
    cin>>y;
    multi=x*y;
    cout<<"multiply of 2 numbers\t"<<multi;
    break;

    case 4: cout<<"DIVIDE\n";
    cout<<"Enter number1\n";
    cin>>x;
    cout<<"Enter number2\n";
    cin>>y;
    divide=x/y;
    cout<<"divide of 2 numbers"<<divide;
    break;

    default: cout<<"Invalid choice";
  }

       getch();

}

0 comments:

Post a Comment