finding min number in array

how to find the min value of an array? this method works perfect when finding the max number but if i change the if statement to < to get the min it throws me a rubbish random number and im not quite sure why?


int main()

{
int myArray[5];
int min = myArray[0];

cout << "type 5 numbers into array" << endl;
for (int i = 0; i < 5; i++)
{
cin >> myArray[i];
}

for (int i = 0; i < 5; i++)
{
if (myArray[i] > min)
{
min = myArray[i];
}
}
cout << min << endl;
}
Please use code tags when posting code.
http://www.cplusplus.com/articles/jEywvCM9/

> int min = myArray[0];
Do this after you've input all the values.

> if (myArray[i] > min)
If you want the minimum, use < instead.
my bad posted with it wrong way around when testing diff things when i put it < way it throws me a random number instead of the min number and when posted > it does gives me max like i expect
all good found solution i had to initialize my min and max value after the user input rather then before and fixed my problem.
Topic archived. No new replies allowed.