2 Replies - 313 Views - Last Post: 27 June 2012 - 11:32 AM Rate Topic: -----

#1 jessica11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is online

  • member icon


Reputation: 4148
  • View blog
  • Posts: 12,936
  • 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
Was This Post Helpful? 0
  • +
  • -

#3 jessica11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1