title: Line regression using vectors
body: <pre><code>#include &lt;iostream&gt;
  
  #include &lt;vector&gt; 
  
  struct Result
  {
    double A;
    double B;
  };
  
  class Regression
  {
  
    struct Point 
    {
      double x;
      double y;
    };
  
    std::vector&lt;Point&gt; points{};
  
    public:
    void add(double x, double y) 
    {
      Point const p{x, y};
      points.push_back(p);
    }
    
    int N = points.size();
  
    double sum_x(std::vector&lt;Point&gt; points)
    {
        double sum = 0;
        for (Point n : points){
            sum = sum + n.x;
        }
        return sum;
  
    }
  
    //and so on for sum_y, sum_xy, sum_x2 (to shorten the question)
  
      double sum_x = sum_x(points);
      double sum_y = sum_y(points);
      double sum_xy = sum_xy(points);
      double sum_x2 = sum_x2(points);
  
   
  
    Result fit() const
    {
      double const d = (N * sum_x2  - sum_x * sum_x);
      double const a = (sum_y * sum_x2 - sum_x * sum_xy) / d;
      double const b = (N * sum_xy - sum_x * sum_y) / d;
      return {a, b};
    }  
  };
  </code></pre>
  <p>Hi, I can't make this code work, for every sum_x, sum_y, etc in the function fit() the error states &quot;expression must have arithmetic or unscoped enum type&quot;.
  I'm really new to c++ so I apologize if this is a trivial mistake.
  Thanks</p>