I'm writing a function that returns the maximum element of an array. I made an array that had 10 elements. For some reason I keep getting these errors and im not sure why. Any help would be greatly appreciated, thank you.
These are my errors:
And the following is my code.Code:max.cpp(25) : error C2065: 'size' : undeclared identifier (26)error C2065: 'a' : undeclared identifier (26) : error C2109: subscript requires array or pointer type
Code:#include <iostream> using namespace std; int max (void);//prototype int main() { const int size=10; int a[size]={1,2,3,4,5,6,7,8,9,10}; max();//call cout<<"The max number is"<<max<<endl; return 0; } int max(void)//function that returns maximum element of array { int MAX=10; int x=MAX; for (int i=0; i<size;i++) if (a[i]==x) return x; }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.