Summation calculator of integers, squares, and cubes
Refactor IO

In each case of your switch statement, you have this at the very beginning:


std::cout &lt;&lt; restraint &lt;&lt; std::endl;
std::cout &lt;&lt; request_range_1;
std::cin &gt;&gt; range_1;

std::cout &lt;&lt; request_range_2;
std::cin &gt;&gt; range_2;



Rather than re-writing this out for each case, you should refactor this to its own function that returns the two inputs. That way, you can just call that function to get the inputs.

Also, speaking of inputs...



Never trust the user!

When you are grabbing the two input numbers for an operation, you show the user a restraint message that says that the first number must be smaller than the second. While your function technically do "handle" this by returning 0, it would be good practice to not call those functions at all and to instead print out to the user if they accidentally (or purposely) entered a bigger number first.

You could include this in the extracted input-getting function described above. You can even create a loop inside this that repeatedly asks the user for proper input before actually returning the input.



early exit -- early exit -- early exit -- early exit....


    if(choice == 'd')
        break;
}
std::cout &lt;&lt; "Calculator OFF" &lt;&lt; std::endl;



This is a bit of code I grabbed from the end of the switch statement. Note that the only time that this bit of code is going to be reached is if the user hit d as their input.

Therefore, you can do some simplifying here. Rather than exiting from the switch statement only to do another conditional on whether or not to break the loop, just return from the entire program as soon as it is discovered that the user entered 'd':

case 'd':
    std::cout &lt;&lt; "Calculator OFF" &lt;&lt; std::endl;
    return 0;


This is much simpler and removes the redundancy from your code.



More refactoring and simplification

Your three _sum functions are all very similar except for a single line. These lines:


int_sum += a;



and


squ_sum += a*a;



and


cub_sum += a*a*a;



The rest of the code in the function is identical (of course, except for the variable names). This means that we can do some refactoring.

To simplify the code, let's write a blank function that follows the same format as the others:

int sum_exponent_series(int a, int b, int exp);


Notice the last parameter: this will allow the function to know whether to put a, a*a, or a*a*a... Which, in fact, can be simplified using &lt;cmath&gt;'s pow.

Now, the body of the function looks like this:

int sum(0);
for(; a &lt;= b; a++) {
    sum += pow(a, exp);
}
return sum;


Note, I made two other changes:


I fixed your indentation (watch that in the future)
I turned your while loop into a for loop. An incrementation at the end of a while loop like you is a pretty good indication you need a for loop.


Now, instead of having three functions, you can just have this one function and call it with different exp values.

BUT WAIT!! You can make your program even more flexible now! Rather than having the user enter the "type" of exponent series thing they want, have them input these three things:


A number
The amount of times to add that number
The exponent to raise the number to when adding


That way, you won't even need a switch statement at all! The user could enter numbers like 3, or 8, or anything else without having to be restricted by what options you already set in place!