C++ - algebraic expressions calculator by addition I'm ultra new to programming. I basically know only IFs, loops, variables. This is first time I used functions in my code and I'm not sure if I understand them correctly.

Basically it is a calculator that requests two natural positive numbers on input, and outputs it's addition, subtraction, multiplication, division and exponentiation. The only rule is: you can use only addition when calculating these expressions. I'm ultra new to programming. I basically know only IFs, loops, variables. This is first time I usentiation. It does not yet support: using '0' as input, using negative numbers as input, using floating point numbers as input, indivisible numbers.

My question is: can you please take a look at my code and just tell me if I made any mistakes that literally burn your eyes? What should I fix? What is especially bad?

#include &lt;iostream&gt;
using namespace std;

int addition(int a, int b)
{
    return a + b;
}

int subtraction(int a, int b)
{
    return a + (-b);
}

int multiplication(int a, int b)
{
    int result = a;
    for (int i = 1; i &lt; b; i++)
        result += a;
    return result;
}

int division(int a, int b)
{
    int counter = 0;
    if (a % b == 0) {
        do {
            a = subtraction(a, b);
            counter++;
        } while (a &gt; 0);
        return counter;
    }
    else
        return false;
}

int exponentiation(int a, int b)
{
    int result = 1;
    for (int i = 1; i &lt;= b; i++)
        result = multiplication(result, a);
    return result;
}

int main()
{
    int numberA, numberB;
    cout &lt;&lt; "Insert two positive natural numbers: ";
    cin &gt;&gt; numberA &gt;&gt; numberB;
    cout &lt;&lt; "\nAddition: " &lt;&lt; addition(numberA, numberB) &lt;&lt; '\n';
    cout &lt;&lt; "Subtraction: " &lt;&lt; subtraction(numberA, numberB) &lt;&lt; '\n';
    cout &lt;&lt; "Multiplication: " &lt;&lt; multiplication(numberA, numberB) &lt;&lt; '\n';
    cout &lt;&lt; "Division: " &lt;&lt; division(numberA, numberB) &lt;&lt; '\n';
    cout &lt;&lt; "Exponentiation: " &lt;&lt; exponentiation(numberA, numberB) &lt;&lt; '\n';
    return 0;
}
Namespaces

You almost never want to write using namespace std; - this is a very common code complaint on this site with C++. The two main reasons are:


it's good to know when you're using stuff from the standard library explicitly, 
standard library names can collide with your own since they've picked the best names!




auto

Consider also using return type deduction here as your functions are fairly trivial, and the following would work:

auto addition(int a, int b) { return a + b; }


The compiler has no trouble working out the return type is clearly an integer, and this will apply to other cases. Another use of auto is in your copy in the multiplication function, for example,

auto multiplication(int a, int b){
    auto result = a;
    // rest of code
}


You can apply this to a lot of other statements in your code. Depending on your style preference and the importance you place on uniformity, you can use the uniform initialisation syntax, auto result{a}.



Division

There's a problem in your division function. It returns counter which is an integer, and the return type is an integer - that's fine. But it can return false.

This compiles, and returning false will be like returning zero, but just do that explicitly, your return type isn't bool.

I would also move the declaration of the counter variable to inside the if statement, since if that statement fails, you don't need it. 

So, if the integers don't exactly divide each other, you don't want to handle that case and you return zero. But you don't check this when outputting to the user. They'll get zero, so I'd opt for an explicit message, since that can have multiple interpretations. 



In C++, return 0 is not required explicitly in main, so omit it. There's also an argument against it along the lines of, if you do include it, it's suggesting main can fail and that there are potentially other error codes that one must check for.