2013-09-16, 01:41 AM
So, your program now compiles and runs, but doesn't do what you expect it to.
Now is when you start debugging.
If your development environment has a debugger, use that. Otherwise, add "debug messages" so you can see what it's doing.
Like so:
Now is when you start debugging.
If your development environment has a debugger, use that. Otherwise, add "debug messages" so you can see what it's doing.
Like so:
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)
{
cout << "Read value: " << value << endl;
sqValue = value * value;
sqSum += sqValue; //Add sqValue to sqSum
cout << "Its square is " << sqValue << ", so the sum of all squares so far is " << sqSum << endl;
}
return sqValue;
}
