actually I'm creating a menu, and the first option prints random integers, and the second option will find the high, low, and average of those random numbers created. I created this, the first part works, but I'm having difficulties getting the high, low, and sum.
< const int LENGTH =100;
int array[LENGTH];
srand(((unsigned)time(0)));
if(input==0){
int cnt = 0 ;
cout << "Enter the length of the array: " ;
cin >> cnt ;
if( cnt > LENGTH ) cnt = LENGTH ;
for( int i = 0; i < cnt ; ++i )
array[i] = 1 + rand() % 100;
for( int i = 0; i < cnt ; ++i )
cout << array[i] << ' ' ;
cout << '\n' ;}
if (input ==1){
int sum = 0;
int average = 0;
int high = array[0];
int low = array[0];
int cnt=0;
for (int dx = 0; dx < cnt; dx++)
{
sum += array[dx];
if(array[dx] > high) high = array[dx];
if(array[dx] < low) low = array[dx];
average = sum/ cnt;
}
cout << high << low << average << endl;
}
average is computed outside the loop, once -- it only works once you have found SUM. (it should be ok as-is but it is not really 'right' to do it every iteration).
otherwise it looks more or less correct. What is not working when you run it?