Head add

Menu Driven C++ Program for a Simple Calculator

    Write a menu-driven program to perform arithmetic operations in c++

    Menu-driven program in c++ for a simple calculator that performs the following operations: Addition, subtraction, multiplication, division of two numbers.

    Write a menu-driven program in c++ for a simple calculator that performs the following operations:
    1. Addition of two numbers
    2. Subtraction of two numbers
    3. Multiplication of two numbers
    4. Division of two numbers

    Write a Menu Driven C++ Program for a Simple Calculator

    Menu-driven program in c++ for a simple calculator which performs the following operations: Addition, subtraction, multiplication, division of two num.

    #include<iostream>
    using namespace std;
    int main()
    {
    char fav;
    int num1,num2,choice,i;
    cout<<"\n Enter 1st Number:";
    cin>>num1;
    cout<<"\n Enter 2nd Number:";
    cin>>num2;
    do{
    cout<<"\n Press 1 for Addition";
    cout<<"\n Press 2 for Subtraction";
    cout<<"\n Press 3 for Multiplication:";
    cout<<"\n Press 4 for Division";
    cout<<"\n Enter your choice:";
    cin>>choice;
    switch(choice)
    {
    case 1: cout<<"\n Sum of "<<num1<<" and "<<num2;
                cout<< " : "<<num1+num2;
                break;
    case 2: cout<<"\n Subtraction of "<<num1<<" and "<<num2;
                cout<< " : "<<num1-num2;
                break;
    case 3: cout<<"\n Multiplication of "<<num1<<" and "<<num2;
                cout<< " : "<<num1*num2;
                break;
    case 4: cout<<"\n Division of "<<num1<<" and "<<num2;
                 cout<< " : "<<num1/num2;
                 break;
    default: printf("\n wrong choice");
    }
    printf("\n Do you want to continue?(y/n)\n");
    scanf("\n %c",&fav);
    }while(fav=='y');
    }

    Output for Menu Driven C++ Program for a Simple Calculator:

    Enter 1st Number:56
    Enter 2nd Number:23
    Press 1 for Addition
    Press 2 for Subtraction
    Press 3 for Multiplication
    Press 4 for Division
    Enter your choice:2
    Subtraction of 56 and 23: 33
    Do you want to continue?(y/n)n

     Menu Driven C++ Program for a Simple Calculator using functions

    In this program, we are going to make a simple calculator using functions in c++. if you are facing any issue in compiling this program, you can comment below in the comment section.

    #include<iostream>
    using namespace std;
    void addition(int a, int b);
    void subtraction(int a, int b);
    void multiplication(int a, int b);
    void division(int a, int b);
    int main()
    {
    char fav;
    int num1,num2,choice,i;
    cout<<"\n Enter 1st Number:";
    cin>>num1;
    cout<<"\n Enter 2nd Number:";
    cin>>num2;
    do{
    cout<<"\n 1. Addition";
    cout<<"\n 2. Subtraction";
    cout<<"\n 3. Multiplication:";
    cout<<"\n 4. Division";
    cout<<"\n Enter your choice:";
    cin>>choice;
    switch(choice)
    {
    case 1: addition(num1,num2);
                break;
    case 2: subtraction(num1,num2);
                break;
    case 3: multiplication(num1,num2);
                break;
    case 4: division(num1,num2);
                 break;
    default: printf("\n wrong choice");
    }
    printf("\n Do you want to continue?(y/n)\n");
    scanf("\n %c",&fav);
    }while(fav=='y');
    }
    void addition(int a,int b)
    {
        cout<<a<<"+"<<b<<"="<<a+b;
    }
    void subtraction(int a,int b)
    {
        cout<<a<<"-"<<b<<"="<<a-b;
    }void multiplication(int a,int b)
    {
        cout<<a<<"*"<<b<<"="<<a*b;
    }void division(int a,int b)
    {
        if(b==0)
        cout<<"\n Denominator can't be zero";
        else
        cout<<a<<"/"<<b<<"="<<a/b;
    }

    Recommended posts:

    Siddharth Jha
    • Hackerrank 5* • Full Stack Developer • Masters in SEO

    Related Posts

    Post a Comment