# How do you use for statement to find the average of a rates array?

Page 1 of 1

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

### #1 jessica11

Reputation: 0
• Posts: 7
• Joined: 22-June 12

# How do you use for statement to find the average of a rates array?

Posted 27 June 2012 - 11:12 AM

I need help using a for statement to find the average of a rates array.
Here is what I have so far:

```#include <iostream>
using namespace std;

double getSum (double ratesUsed[], int numElements);

int main ()
{
double rates [5] = {3.4, 56.7, 8.99, 11.23, 4.67};
double sum = 0.0;
double average = 0.0;

cout << "Average: " << sum / 5.0 << endl;

system("pause");
return 0;
}	//end of main function

double getSum (double ratesUsed[], int numElements)
{
double sum = 0.0;

for (int sub = 0; sub < numElements; sub += 1)
sum += ratesUsed[sub];

return sum;
}	//end of getSum function

```

which this code does build it just doesn't show what it's suppose to (rates & average).

Is This A Good Question/Topic? 0

## Replies To: How do you use for statement to find the average of a rates array?

### #2 jimblumberg

Reputation: 4736
• Posts: 14,768
• Joined: 25-December 09

## Re: How do you use for statement to find the average of a rates array?

Posted 27 June 2012 - 11:16 AM

Where are you actually calculating the sum. You have a function to do this but you never call that function.

Jim

### #3 jessica11

Reputation: 0
• Posts: 7
• Joined: 22-June 12

## Re: How do you use for statement to find the average of a rates array?

Posted 27 June 2012 - 11:32 AM

Oh yeah! Thanks so much!