Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating and implementing functions (C++).
#13
SaptaZapta Wrote:Ouch. I didn't notice that either.
Seems you've got the hang of it, though. Have fun.

Ahh... not quite. I mean, I do, but now getting the variance is becoming a challenge.

Can I call a function within a declared function? I've got this down...

Code:
float Variance(int numValues, float avg, float squaresSum);

float Variance(ifstream &inF, int numValues, float avg, float squaresSum)
{
    //Start from the beginning of the file - Rewind.
    inF.clear();
    inF.seekg(0L, ios::beg);

    //Variance = sumofsquares/#values - average*average (when numValues>0);
    float variance = 0;
    avg = Sum (inF) / InputCount (inF);
    variance = SumOfSquares (inF) / InputCount (inF) - avg * avg;
    return variance;
}

And this is within the main function:

Code:
//Prints the variance of the values in file.
cout << "VARIANCE = " << Variance (inF, numValues, avg, squaresSum) << endl;

The error I get is that numValues, avg and squaresSum are undeclared variables. I tried declaring them within the function but it just gave me the same error and the error lies on the line where I'm trying to print the variance. Sad
Reply


Messages In This Thread
Creating and implementing functions (C++). - by MariettaRC - 2013-09-16, 02:26 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)