Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating and implementing functions (C++).
#10
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:
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;
}
Reply


Messages In This Thread
Creating and implementing functions (C++). - by SaptaZapta - 2013-09-16, 01:41 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)