2013-09-16, 01:31 AM
All right, fair enough. I've tried passing by reference and it just created a whole mess for me, so I just went with declaring within functions. o_e I'll have to devote some time to understanding how to pass by reference.
Now I've run into another problem.
This is giving me 36 as an end result (since 6 is the last number and there are 7 values in my test file), meaning that it's acting as if sqSum is always 0, and that's been declared outside of the loop. I'm not sure what I could have done wrong here.
Now I've run into another problem.
Code:
float SumOfSquares (istream &inF)
{
//Start from the beginning of the file - Rewind.
inF.clear();
inF.seekg(0L, ios::beg);
float sqValue = 0;
float sqSum = 0;
float value;
while (inF >> value)
{
sqValue = value * value;
sqSum += sqValue; //Add sqValue to sqSum
}
return sqValue;
}This is giving me 36 as an end result (since 6 is the last number and there are 7 values in my test file), meaning that it's acting as if sqSum is always 0, and that's been declared outside of the loop. I'm not sure what I could have done wrong here.

