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;
}
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