oh no problem. Im not sure let me look at that real quick
edit: what do you mean print the one value in the file. Your fillvector should read it into the vector and it should then be in the vector and that loop would print it??
i think it has to do with the while statement in the fill vector. i think it is accidently reading in garbage to the vector or something for when there are no numbers or 1 number.
Say theres one value in the text file. The current function that prints the values to the screen will always do it once then want to do it again. If there is no other value it errors because its looking for one that isnt there right? If thats correct I think we need to put something in the loop that protects from having one number in the file like
v is a vector. You mean to say v.size(). the size of the vector at minimum can be zero. Even if this were the case it should still have no problem printing nothing to the screnn because this loop would be perfectly ok
for(int i = 0; i < v.size(); i++) // this will fail the first test and thats fine theres no numbers in the vector.
wait dont change anythng yet. I just commented out everything all the prints and only read in the vector and got no errors etc. so it might be the prints. Im bout to comment out sections to see where the problem stems from
template <typename T>
double median(const vector<T> & v)
{
int length = v.size();
double median = 0; // set to 0 in case no number is in file
if(length == 1)
return v[length-1];// if size ==1 v[1] is accessing out of range
elseif( length % 2 == 0 ) // even
{
median = (v[length/2] + v[(length/2)-1]) / 2;
}
else // odd
{
median = v[length/2];
}
return median;
}
divide and conquer my friend. divide and flippin conquer. I just commented out most of the code until it worked then I started uncommenting parts. and the median line was giving issues. then i just went there and examined it.
Well thanks for all the help. Most likely couldn't have done this with out your help. Anyways I need to get some sleep cause i have a final in less then 6 hours!