944,140 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2421
  • C++ RSS
Nov 11th, 2004
-1

question about array

Expand Post »
hi, all.
i have some problems to do array.
i am supposed to get the average and sum in given number of array.
but, i only got 1 in my all answers.
please, tell me what was wrong in my program.
thank you.

//hw for array



#include <iostream>

#include <iomanip>

#include <cmath>


using namespace std;



float ave(float x[],int n);

float sum(float x[],int n );

float diff(float x,float y);

float large(float x[],int n );

float small(float x[],int n);



const float size=10;


int main()

{


float array[10]={24.9,18.5,7.9,14.3,56.1,37.8,41.5,28.3,32.7,19.4};


cout<< "\na) \n\n";

cout<<"\naverage of these numbers: "<<ave<<endl;



return 0;

}



float ave(float x[],int n)

{
int i;
float sum=0;

for (i=0;i<n;i++)

sum +=x[i];

return (sum/n);

}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sweetbaby is offline Offline
2 posts
since Nov 2004
Nov 11th, 2004
0

Re: question about array

cout<<"\naverage of these numbers: "<<ave<<endl;

You are not passing any of you parameters in ave. I am surpised it is compiling at all. Should look like ave(array, 10).
Reputation Points: 11
Solved Threads: 2
Junior Poster in Training
jasweb2002 is offline Offline
56 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: never to old
Next Thread in C++ Forum Timeline: help with first and second problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC