Thread: keep getting a sum of 0

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    32

    keep getting a sum of 0

    I have tried several times to make minor tweaks to the program, but nothing seems to work, i finally ended with
    Code:
    double Mean(vector<double> L)
    {  
       double sum=0;
       vector<double> list1;
       
       for(int i=0;i<list1.size();i++)
       {sum=sum+list1[i];}
       
       return sum;
    }
    as soon as i can figure out how to get a value other than 0, i will add in the "/list1.size()" after the return sum line.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You are adding up elements in an empty vector, what did you expect?

    May-be you meant to add up items in the vector called L.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    32
    Thank you anon, i changed all my L's to list1 and that fixed the problem, i hate minor problems like that that cause major headaches

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    there is no reason to use list1, just use L

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    32
    i would, but im already using L in L_side for a different part of my program, and it was easier to keep things organized with just calling it list1
    Last edited by Creatlv3; 05-07-2010 at 04:38 PM.

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    If I may ask, what did you do with the vector originally called list1?

  7. #7
    Registered User
    Join Date
    Feb 2010
    Posts
    32
    i was trying to use it to calculate the mean and median of a set of numbers, however there was nothing in it, so it was never working. everything works fine on it now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Application Repeatition
    By lgcarter in forum C Programming
    Replies: 3
    Last Post: 06-16-2009, 02:07 PM
  2. Replies: 1
    Last Post: 05-28-2009, 01:28 PM
  3. Minor Problem
    By stewie1986 in forum C Programming
    Replies: 6
    Last Post: 11-30-2007, 08:40 AM
  4. a sum equal to or in excess of 100
    By lyoncourt in forum C Programming
    Replies: 6
    Last Post: 10-07-2007, 05:43 PM
  5. string to int conversion not using atoi()
    By linucksrox in forum C Programming
    Replies: 2
    Last Post: 05-19-2004, 12:17 AM

Tags for this Thread