Thread: Invalid operands to binay

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    19

    Invalid operands to binay

    I'm making a function to calculate variance and this is the error that I'm getting.

    My code is:

    Code:
    double variance(int totnum, double data[])    {
            int i=0;
            double variance=0, sum=0;
            
            for (i=0;i<totnum;i++)
        {
            sum += pow((data[i] - mean), 2);
        }
    
    
        variance = sum/totnum;
    
    
        return variance;
    
    }

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Actually I don't get an error about invalid operands. This is the error:
    Code:
    Error	1	error C2065: 'mean' : undeclared identifier	c:\users\josh2\documents\visual studio 2013\projects\sandbox\sandbox\source.cpp	9	1	sandbox
    And that is if the math library is included for pow().

    Make sure you've provided a Short, Self Contained, Correct Example.

  3. #3
    Registered User
    Join Date
    Feb 2015
    Posts
    19
    Forgot about that one. Well the mean was just a double, so if you initialize that, then you should get the error that I'm getting. And I do have the math.h included.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    With mean defined and initialized, the code you've pasted compiles for me.

  5. #5
    Registered User
    Join Date
    Feb 2015
    Posts
    19
    Thanks man, made me look into something else.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Invalid operands to binary %
    By 4531144 in forum C Programming
    Replies: 2
    Last Post: 10-30-2013, 04:05 AM
  2. invalid operands to binary?
    By Thomas_W in forum C Programming
    Replies: 3
    Last Post: 12-16-2012, 04:15 AM
  3. Invalid Operands
    By chocobo59 in forum C Programming
    Replies: 6
    Last Post: 10-12-2007, 04:27 PM
  4. Invalid operands to binary *
    By jrfall349 in forum C Programming
    Replies: 8
    Last Post: 03-31-2007, 11:15 PM
  5. invalid operands
    By simhap in forum C++ Programming
    Replies: 5
    Last Post: 10-08-2001, 10:23 AM