Hi,

I've been working on this a few days and I'm kinda stuck. my error is in line 38-

average =ave(&ParentsAge,sizeof(ParentsAge));

If anyone has any ideas as to what I am doing wrong, I would love to finally figure this out!! Thanks

  #include <iostream>
  using namespace std;

  void displayTitle ()
  {
          cout << "Calculate the Average Age of Parents seeking Invetro" << endl;
   }
   double ave (int *array, int asize)
  {       
          double average;
          double sum;
          for (int i = 0; i < asize; i++)
            {       
              sum += array[i];
           }       
          average=sum/asize;
          return ( average );
  }       
  int main ()
          {
          displayTitle ();
          double ParentsAge[10], age1, average; //declaring array as integer
          int i, sum; //declaring age1 sum and integer
          sum = 0;
          for (int i = 0; i < 10; i++)  //for loop to keep count
          {
                  cout << "Enter 10 parents age: " << ( i + 1 ) << endl;
                  cin >> age1;  //input of ages
                  if (age1 != 0) {
                  ParentsAge[i] =age1;  //adding ages together
                  }
                  else {
                  (age1 == 0);
                  cout << "Enter a valid age" << endl;
                  i--;
                  }
          }
          average =ave(&ParentsAge,sizeof(ParentsAge));
          cout << endl ;
                  cout << "Average age of Parents seeking Invetro is: "<< average << endl;   //output of averages
          return (0);
  }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Well, some code tags & code formatting would help us help you. It also helps to know what your error is.

Regardless, I'm going to assume that the compiler is spitting back an error saying that it's throwing back that ave needs a different type of variable passed into it. With that guess (however wrong it may be), ParentsAge itself is a pointer (as are all arrays). Just pass ParentsAge instead of &ParentsAge.

Hi Sodabread,

Thanks, you were right about the pointer. I am so sorry about the lost formatting when I pasted. Here is a a better copy of where I am at now, I made a few changes to the function. Thanks again for your patience, I am really new at this. Eris32

http://codepad.org/X6u0Noqn

Edited 6 Years Ago by Eris32: n/a

Solved it!!!! Thank you, it was an error with my sum declaration!!

This question has already been answered. Start a new discussion instead.