building an array project - error message error C2660: 'FindAvg' : function does not take 1 parameters


2 replies [Last post]
GalaxyM31
GalaxyM31's picture
Offline
Joined: 2012-03-22
Points: 0

This is the only error message I have left to fix. I've tried everything I can think of. Please help!

Here is where it points the error message too:

 //find the average of numbers in array a
 float Average;
 FindAvg(a);

this is the related user defined function:

void FindAvg(int a[])
{
 int Total = 0;
 for (int i = 1; i < 10; ++i)
 {
  Total += a[i];
 }
 float Average = Total/10;
}

 

If more information is needed, please let me know.

 

Thanks, anyone who can help!

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
A_S
A_S's picture
Offline
A Coding BeautyW007! I watched 10 vids!
Joined: 2011-10-30
Points: 110

The required parameter for FindAvg is an array of intergers. You are passing a single float. The problem is that you are passing the wrong type of argument. 

this should work

 

#include "stdio.h" ////// I wrote this in C, but this function will work in a C++ program too

float FindAvg(float a[], int size)          /// you need to specify how many elements are in the array

/// I also would expect that you want to return the average so that's why I have it return a float

{

  float Total = 0.0;

int i;

  for (i = 0; i < size; i++) /// arrays start at 0 not 1      /// also use the postincrement operator  "i++" instead

  {

Total += a[i];

  }

float Average = Total/size;

return Average;

}

int main()

{

float myNumbers[] = { 1.2, 2.3, 3.4 }; //////    you can change and/or add values

printf("%f\n",FindAvg(myNumbers, sizeof(myNumbers)/sizeof(float))) ;

return 0; // the sizeof operator tells how many bytes something takes up in memory

/// so if you take the total number of bytes in the elemetns take up and divide that number 

/// by the size of each element, then you get the number of elements

}

 

GalaxyM31
GalaxyM31's picture
Offline
Joined: 2012-03-22
Points: 0

Thanks! I will give this a try. Also, thanks for including "why" I need to write it that way. It's difficult to get help from my classmates! I think they want to keep all the information to themselves! Hahaha! Or I just need to reconsider my major, this is some very difficult stuff! :-)