problem in recursion

hello i try to write a recursive programm that will return the segond largest array in the random array,

can you help please to understand what it wrong?

thank you very much

#include <iostream>
#include <stdlib.h>

using namespace std;

#define SIZE 10
int new_max( int i[], int size)
{
int max, newmax; if (i!= NULL)//the condition for stopping in random
return newmax;

if (i[size] < max)
{
if (i[size]< newmax)

i++;
new_max(i,size);
}

else
{
newmax = i[size];
i++;
new_max(i,size);
}

if (i[size] > max)
{
newmax = max;
max = i[size];
i++;
new_max(i,size);
}

}

void main()
{
int array[SIZE];//random numbers until 100 to the array
cout<<"The array is: ";
for (int i=0; i<SIZE; i++)
{
array[i] = rand() % 100;

cout<<array[i]<<" ";

}
cout<<endl;

cout<<"The second minimum is: "<<new_max(array,SIZE)<<endl;

}
1
2
3
if ( i != NULL ) { //the condition for stopping in random 
    return newmax;
}

I think you mean if ( i == NULL )
1) As Fransje said
2) You doesn't returning anythin at the end of new_max()
3) you are using max and newmax without initialization.
Topic archived. No new replies allowed.