Single neuron in neural network using c++
<p>I am trying to write a simple neuron function in c++ similar to this image. I am using sigmoid function as activation function.
<a href="https://i.stack.imgur.com/7mTvt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7mTvt.jpg" alt="enter image description here"></a></p>

<p>This is my c++ neuron function</p>

<pre><code>#include&lt;math.h&gt;

double neuron(double layer_inputs[],int iter)
{

  // Feed forwarding single neuron
    double network=0;
    double bias=1;
    double activation;

    //get number of elements in the layer
    const int num=sizeof(layer_inputs)/sizeof(layer_inputs[0]);
    double weight[num];

    for ( int i = 0; i &lt; num; i++ )
    {
        if(iter==0)
        {
        //first time assigning random weights
            weight[i]=rand();
        }

        //feed forwarding summation
        network=network+(layer_inputs[i]*weight[i]+bias);


    }

    activation= 1.0 / (1.0 + exp(-network)); //sigmoid activation function

return activation;
}
</code></pre>

<p>The problem is I dont know whether I made any logical error in my code. <code>iter</code> is the iteration variable to check if the neuron is activating for first time. Is my writing the neuron in a neural network correct.</p>

<p>EDIT:</p>

<p>Even though not from a programmatic or quant background I am fascinated about programming,neural networks and artificial intelligence. I hve used inbuilt functions in <code>caret</code> R but for more understanding  I want to create a simple neural network from scratch. I learned most of the basics from internet and I am posting my codes here because I am sure I made some illogical but executing script.</p>

<pre><code>#include&lt;iostream&gt;
#include &lt;math.h&gt;//pow, exp
#include "sqrtnn.h" //neuron()


int main()
{

    double input[]= {1,4,9,16,25,36,49,64,81,100};
    double output[]= {1,2,3,4,5,6,7,8,9,10};
    //number of layers
    double layer=3;
    double output_network[10];
    double error[10];
    double learning_rate=0.02;
    //number of iterations
    int iter=10;
    int input_num=sizeof(input)/sizeof(input[0]);
    std::cout&lt;&lt;"Simple  neural network for solving square root\n \nINPUT -&gt; OUTPUT\n\n";
    for ( int i = 0; i &lt; iter; i++ )
    {
        for ( int j = 0; j &lt; input_num; j++ )
        {
            for ( int k = 0; k &lt; layer; k++ )
            {
                //feed forwarding
                output_network[j] =neuron(input,i) ; //sigmoid activation function

                //back propogation
                error[j]=1/2*pow(output[j]-output_network[j],2);//error function
                std::cout&lt;&lt;input[j]&lt;&lt;" -&gt; "&lt;&lt; output[j]&lt;&lt;"= "&lt;&lt; error[j] &lt;&lt;"\n";


            }
        }
    }


    return 0;
}
</code></pre>