Displaying Highest Value in Array Help

Hello all,
I'm new to forums and was looking for assistance with a C++ program essentially, I need it to display the index of the highest value in an array using a function I keep getting the error error C2447: '{' : missing function header (old-style formal list?). when i run the following code. Can anyone give me advice?

# include <cmath>
# include <string>
using namespace std;

int i,x;

int maxElement(int a[],int size);

int main()
int element[5];
int number_of_elements=5;



int maxElement(int a[],int size);

if (element[i]>x)


return x;
To remove that error, simply remove ';' at int maxElement(int a[],int size); .

But after remove this error, you will realize that there will have other errors. For example, in your function int maxElement(...) , the for loop, it should be ';' instead of ','. Then there is a variable 'element', you might need to check this too.

Also you might need to check the logic of the code again. For example, i, is the index of the array, not the content of the element, so why do you put i = x.

Then for in your main, you declare int element[5] , but you did not initialize any value. You might need to initialize 5 values to it?

Hope it helps :)
Thank you very much. It worked!
Topic archived. No new replies allowed.