I wrote this simple code that should calculate the highest number of a series of array elements but the results are strange, i'm pretty sure it has something to do with the way I wrote but I can't figure out what I did wrong
I tried the same code on c++ shell and it gave me different results
#include <iostream>
using namespace std;
int main()
{
int size,c,max;
cout<< "enter the size of the array" << endl;
cin>> size;
int a[size];
max=a[0];
cout <<"fill the array" << endl;
for(c=0; c<size; c++){
cin>>a[size];
if(max<a[size]){
max=a[size];
}
}
cout<<"the highest number is:"<<max;
}
enter the size of the array 5 fill the array 1 2 3 4 5 the highest number is:27 Process returned 0 (0x0) execution time : 14.653 s Press any key to continue.
enter the size of the array 7 fill the array 1 2 3 4 5 6 7 the highest number is:27 Process returned 0 (0x0) execution time : 14.653 s Press any key to continue.
enter the size of the array 8 fill the array 1 2 3 4 5 6 7 8 the highest number is:8 Process returned 0 (0x0) execution time : 5.915 s Press any key to continue. (if the size of the array is over 8 it works)