Calculator in C++
C++ Programming

Calculator in C++

 

Calculator that performing as calculator which allows all Arithmetic Operators with operands as input

#include<iostream.h>

#include<stdlib.h>

#include<conio.h>

int calculator(int a,char c,int b)

{

    int h,w,x,z;

    float y,m=0.0;

    z=(a+b);

    x=(a*b);

    w=(a-b);

    h=(a%b);

    y=(a/b);

    m=y;

    switch(c)

    {

    case ‘+’:

        cout<<a<<“+”<<b<<“=”<<z<<endl;

        break;

    case ‘-‘:

        cout<<a<<“-“<<b<<“=”<<w<<endl;

        break;

    case ‘*’:

        cout<<a<<“*”<<b<<“=”<<x<<endl;

        break;

    case ‘/’:

        cout<<a<<“/”<<b<<“=”<<m<<endl;

        break;

    case ‘%’:

        cout<<a<<“-“<<b<<“=”<<x<<endl;

        break;

    default:

        cout<<“Error Input Program Terminated”<<endl;

        break;

    }

    getch();

    return 0;

}

void main()

{

    int a,b,x;

    clrscr();

    char c,y;

    cout<<“Welcome To My Calculator:”<<endl;

    cout<<“Enter to calculate:”<<endl;

    start:

    cin>>a>>c>>b;

    calculator(a,c,b);

    cout<<“If you want to calculate more then press Y else N”<<endl;

    cin>>y;

    if(y==’y’ || y==’Y’)

    goto start;

    else if(y==’N’ || y==’n’)

    exit(0);

}

Calculator in C++

Recommended Posts

C++ Programming

Visibility modes in C++

In C++, visibility modes refer to the accessibility of class members (such as variables and functions) from different parts of a program. C++ provides three visibility modes: public, private, and protected. These modes control the access levels of class members concerning the outside world and derived classes. Public: Members declared as public are accessible from […]

Rekha Setia 
C++ Programming

Inheritance in C++

In C++, inheritance is a fundamental concept of object-oriented programming (OOP) that allows you to create a new class based on an existing class, known as the base or parent class. The new class is called the derived or child class. Inheritance facilitates code reuse and supports the creation of a hierarchy of classes. There […]

Rekha Setia 
C++ Programming

C++ Classes and Objects

In C++, classes and objects are fundamental concepts that support object-oriented programming (OOP). Here’s a brief overview of classes and objects in C++: Classes: In C++, a class is a user-defined data type that allows you to encapsulate data members and member functions into a single unit. Classes are the building blocks of object-oriented programming […]

Rekha Setia 

Leave A Comment