Calculator for any number of inputs The "nasty implementation" I mentioned is within the void calculator() inside of calculator.cpp. Everything goes well as long as user don't type in the erroneous syntax. But I think this isn't the good idea to implement it this way.
Can I do it the other way around with more reasonable implementation without losing the functionality of being able to calculate infinitely(not really,I know).

main.cpp:

#include &lt;iostream&gt;
#include "calculator.h"

int main()
{
    calculator();
    return 0;
}


calculator.cpp:

#include &lt;iostream&gt;
#include &lt;cassert&gt;
#include "calculator.h"

int getIntInput()
{
    int x{};
    std::cin &gt;&gt; x;
    assert("Syntax Error!!" &amp;&amp; !std::cin.fail());
    return x;
}

char getOperatorInput()
{
    char x{};
    std::cin &gt;&gt; x;
    bool b{x == '+' || x == '-' || x == '*' || x == '/' || x == '^'};
    assert("Syntax Error!!" &amp;&amp; b);
    return x;
}

int calculate(int x)
{
    char op{getOperatorInput()};
    int tmp{getIntInput()};
    if(op == '+')
    {
        return x + tmp;
    }
    else if(op == '-')
    {
        return x - tmp;
    }
    else if(op == '*')
    {
        return x * tmp;
    }
    else if(op == '/')
    {
        return x / tmp;
    }
    return 0;
}

void calculator()
{
    std::cout &lt;&lt; "Enter your expression : ";
    int64_t result{};
    int loopCount{0};
    do{
            if(loopCount == 0)
                result = getIntInput();
            result = calculate(result);
            loopCount++;
    }
    while(std::cin.peek() != '\n');
    std::cout &lt;&lt; "Your result is : " &lt;&lt; result &lt;&lt; '\n';
}


calculator.h:

#ifndef CALCULATOR_H
#define CALCULATOR_H

int getIntInput();
char getOperatorInput();
void calculator();

#endif // CALCULATOR_H
```
Some general comments:


I think your program is small enough not to warrant any functions. Of course, this can be a matter of taste. It's also reasonable to do input parsing, for instance, in a separate function.
To avoid hardcoding the possible binary operators, I suggest taking a more data-driven approach and storing all possibilities in a suitable container (like a map).
You use integers as your operands, but you support division. Because you truncate the result into an integer type, 1/2 will equal 0 in your calculator. For this reason, you might want to use a floating point type.


We could rewrite your program into the following 50 lines or so:

#include &lt;iostream&gt;
#include &lt;limits&gt;
#include &lt;map&gt;
#include &lt;functional&gt;
#include &lt;cassert&gt;

int main()
{
    typedef std::function&lt;float(float, float)&gt; binary_op;
    const std::map&lt;char, binary_op&gt; binary_ops =
    {
        { '+', std::plus&lt;float&gt;() },
        { '-', std::minus&lt;float&gt;() },
        { '*', std::multiplies&lt;float&gt;() },
        { '/', std::divides&lt;float&gt;() },
        // NOTE: see how easy adding new functionality is.
        { '#', [](float x, float y) { return x * x * x + y; } }
    };

    std::cout &lt;&lt; "Enter your expression: ";
    float result = 0.0;

    float x;
    float y;
    char op;

    if (!(std::cin &gt;&gt; x &gt;&gt; op &gt;&gt; y))
    {
        std::cout &lt;&lt; "ERROR!\n";
        return 0;
    }

    const auto op_iter = binary_ops.find(op);
    // Handle errors as you wish.
    assert(op_iter != binary_ops.end());
    result = op_iter-&gt;second(x, y);

    while (std::cin.peek() != '\n')
    {
        if (!(std::cin &gt;&gt; op &gt;&gt; y))
        {
            std::cout &lt;&lt; "ERROR!\n";
            return 0;
        }

        const auto op_iter = binary_ops.find(op);
        // Handle errors as you wish.
        assert(op_iter != binary_ops.end());

        result = op_iter-&gt;second(result, y);
    }

    std::cout &lt;&lt; "Result: " &lt;&lt; result &lt;&lt; "\n";
}


Comments about this solution:


We do not correctly handle operator precedence. If you want to do this, I suggest looking at something like the Reverse Polish notation.
The std::map now implements the data-driven approach as suggested: you easily add more binary operators as long as they satisfy the required interface. That is, any operator will do as long as it takes two operands (castable to floats) and returns a float. For example, you could add in a fifth line for operator '#' (or whatever you want to call it), and parsing etc. is done automagically for you.