Code for Simple Calculator in C++

Hello Programmers, In this blog post, We will learn to code a simple Calculator in C++. Let’s discuss them in detail:-

calculator code in c++

Code and output for calculator code in C++ is :-

 
#include<iostream>
using namespace std;
int main()
{
    int x,y,cal;
    cout<<“press 1 for multiplication \npress 2 for divison \npress 3 for addition \npress 4 for subtraction \n<<endl;
    cout<<\ninput the value of 1st number”<<endl;
    cin>>x;
    cout<<“input the value of 2nd number”<<endl;
    cin>>y;
    cout<<“what do you want to perform “<<endl;
    cin>>cal;
    switch(cal)
    {
        case 1:
        cout<<“multiply of 2 number is “<<x*y;
        break;
        case 2:
        cout<<“divison of 2 number is “<<endl<<x/y;
        break;
        case 3:
        cout<<“addition of 2 number is “<<x+y;
        break;
        case 4:
        cout<<“subtarction of 2 number is “<<xy;
        break;
        default :
        cout<<“no result”;
    }
    return 0;
}
 

OUTPUT

 

press 1 for multiplication
press 2 for divison
press 3 for addition
press 4 for subtraction

input the value of 1st number
23
input the value of 2nd number
27
what do you want to perform
3
addition of 2 number is 50

 

Hope this blog post was helpful to you and you have got the answer to your question. Thank you for visiting our blog. If you have any doubts about any coding questions then let us know in the comments section we will answer them as soon as possible. Till then check out our more blog posts.

Leave a Comment

Your email address will not be published. Required fields are marked *