-
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.
-
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.
-
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
-
there is no reason to use list1, just use L
-
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
-
If I may ask, what did you do with the vector originally called list1?
-
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