Computing the scalar product of two vectors in C++
<p>I am trying to write a program with a function <code>double_product(vector&lt;double&gt; a, vector&lt;double&gt; b)</code> that computes the scalar product of two vectors. The scalar product is</p>

<pre><code>$a_{0}b_{0}+a_{1}b_{1}+...+a_{n-1}b_{n-1}$.
</code></pre>

<p>Here is what I have. It is a mess, but I am trying!</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;

using namespace std;

class Scalar_product
{
    public:
    Scalar_product(vector&lt;double&gt; a, vector&lt;double&gt; b);
};
double scalar_product(vector&lt;double&gt; a, vector&lt;double&gt; b)
{
    double product = 0;
    for (int i = 0; i &lt;= a.size()-1; i++)
        for (int i = 0; i &lt;= b.size()-1; i++)
            product = product + (a[i])*(b[i]);
    return product;
}

int main() {
    cout &lt;&lt; product &lt;&lt; endl;
    return 0;
}
</code></pre>
