Page 1 of 1

## 3 Replies - 2122 Views - Last Post: 11 June 2009 - 06:11 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=109364&amp;s=ed29a8f7f210b8d45068e861088c66b4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 pigmitten

Reputation: 0
• Posts: 14
• Joined: 04-October 08

Posted 10 June 2009 - 01:22 PM

hi, so I'm doing a class average function for a vector that is storing grades.
my prof wants me to use the accumulation function to determine the average. this is what I submitted:

```double GradeBook::determineClassAverage()   //self explanatory
{
for ( int i = 0; i < grades.size(); i++) {
}

}

return 0;
}

```

" Why do you need this? You're calculating a value you already have available."

howEVER, when I do this, it rounds my averages to the nearest int instead of giving me a double. how do I fix this?
to the best of my knowledge, gradeTotal should equal grades.size() so I don't understand why I am getting two different return values.

anyway,
my test code is this:

```void testClassAverage()
{

//this is where my code goes beserk. well, not beserk. but if i use grades.size() the equality assertion returns false & tells me the average is 74, not 74.75

}

```

much thanks,
pig

Is This A Good Question/Topic? 0

### #2 pigmitten

Reputation: 0
• Posts: 14
• Joined: 04-October 08

Posted 10 June 2009 - 01:22 PM

hi, so I'm doing a class average function for a vector that is storing grades.
my prof wants me to use the accumulation function to determine the average. this is what I submitted:

```double GradeBook::determineClassAverage()   //self explanatory
{
for ( int i = 0; i < grades.size(); i++) {
}

}

return 0;
}

```

" Why do you need this? You're calculating a value you already have available."

howEVER, when I do this, it rounds my averages to the nearest int instead of giving me a double. how do I fix this?
to the best of my knowledge, gradeTotal should equal grades.size() so I don't understand why I am getting two different return values.

anyway,
my test code is this:

```void testClassAverage()
{

//this is where my code goes beserk. well, not beserk. but if i use grades.size() the equality assertion returns false & tells me the average is 74, not 74.75

}

```

much thanks,
pig

### #3 BlakeJustBlake

• D.I.C Regular

Reputation: 26
• Posts: 441
• Joined: 15-February 09

Posted 10 June 2009 - 01:45 PM

Try typecasting it:

```return accumulate(grades.begin(), grades.end(), 0 ) / (double)grades.size();

```

### #4 Kanvus

• D.I.C Regular

Reputation: 42
• Posts: 452
• Joined: 19-February 09