Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Annoying error using arrays, and pointers. What am I missing here?

$
0
0
#include <iostream>
#include <iomanip>

using namespace std;

double aveInt(int *array, int size);
 
int main() 
{
    char pause;
    double avg;
     const int SIZE=5;  
     const int cIntArr[SIZE]= {5, 12, 8, 44, 21};
     //array of  const int pointers
     const int  *cPtrArr[]= {&cIntArr[0], &cIntArr[1], &cIntArr[2], &cIntArr[3], &cIntArr[4]};
     
     avg = aveInt(cPtrArr, 5 );
     
     
     cout<<"Here are the values in cIntArr:\n";
     for (int count=0; count<SIZE; count++)
        { cout<<*(cPtrArr[count])<<" ";
         }
    cout << "Calculated average value is: " << avg << endl;
         cin.get(pause);      
         cin.get();
         return 0;
         }
              
double  aveInt(int *array,int size)
{
  int    i, sum = 0;       
  double avg;          
 
  for (i = 0; i < size; ++i)
  {
    sum += array[i];
   }
 
  avg = double(sum) / size;
 
  return avg;
}



I get the following error and not sure how to fix it:

17 No3.cpp cannot convert `const int**' to `int*' for argument `1' to `double aveInt(int*, int)'

How do I fix this??? It has something to do with const int conversion to double?? I have to use the const int so I don't know exactly how to fix it and make it compile.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>