Demonstration of Pentagonal Number Challenge
  
  Using the C++ language, have the function PentagonalNumber(num) read num which will be a positive integer and determine how many dots exist in a pentagonal shape around a center dot on the Nth iteration. For example, in the image below you can see that on the first iteration there is only a single dot, on the second iteration there are 6 dots, on the third there are 16 dots, and on the fourth there are 31 dots. 
  
  
  
  Your program should return the number of dots that exist in the whole pentagon on the Nth iteration. 
  
  Sample Test Cases

Input:2
Output:6

Input:5
Output:51



I found it weird that Coderbyte called this a hard challenge. It works, but is this the right approach?

Header File

#ifndef PentagonalNum_hpp
#define PentagonalNum_hpp

#include &lt;stdio.h&gt;

class PentagonalNum
{
public:
    PentagonalNum(int N);
    unsigned long long int num_Of_Dots();
private:
    int iteration;
};
#endif /* PentagonalNum_hpp */   


CPP File

#include "PentagonalNum.hpp"

PentagonalNum::PentagonalNum(int N)
: iteration(N)
{
}

unsigned long long int PentagonalNum::num_Of_Dots()
{
    int result = 1;
    int num = 5;

    for (int i = 1; i &lt; iteration; ++i)
    {
        result += num;
        num += 5;
    }
    return result;
}
It seems a little peculiar to use a class to solve this problem. It's not like there's any need to maintain state. All you're doing, in the end, is making it more difficult to use - instead of:

auto result = pentagonal_number(n);


you have to write:

auto pentagonal_number = PentagonalNum{n};
auto result = num_Of_Dots();


or:

auto result = PentagonalNum{n}.num_Of_Dots();


You could throw out the whole class and just keep the num_Of_Dots() member function, let it take iteration as a parameter, and you'd be done. It would be much easier to use, too.

As for the code itself:

#include &lt;stdio.h&gt;


This is not valid in C++ anymore (though it used to be). You need &lt;cstdio&gt;, or better yet, use actual C++ I/O.

unsigned long long int PentagonalNum::num_Of_Dots()
{
    int result = 1;
    int num = 5;

    for (int i = 1; i &lt; iteration; ++i)
    {
        result += num;
        num += 5;
    }
    return result;
}


It seems like this function can be both noexcept and constexpr (and, if it's going to be a class member, also const). Note that the function requires iteration to be greater than or equal to 1; if you're not checking that here so the function can be noexcept, then you should check it in the constructor.

The big question I have is why result is only an int if you intend to return a unsigned long long. Seems a bit of a waste of all that integer range.

You use some magic numbers and variables with mysterious names (num?). Your code would be clearer and easier to understand with more explicit variable names, like:

constexpr unsigned long long int PentagonalNum(int iteration)
{
    // might want to assert that iteration &gt;= 1

    constexpr auto NUMBER_OF_SIDES = 5uLL;

    auto result = 1uLL; // start with 1 point
    auto points_to_add_on_next_iteration = NUMBER_OF_SIDES;

    for (auto i = 1; i &lt; iteration; ++i)
    {
        result += points_to_add_on_next_iteration;
        points_to_add_on_next_iteration += NUMBER_OF_SIDES;
    }

    return result;
}


As an aside, I suspect the reason this challenge was marked as "hard" is because you are supposed to try and solve it without iterating. In other words, you are supposed to stop and think about the problem and derive an equation for the number of dots at iteration n, rather than just charging in and doing an iterative solution.