another smallest/highest value in array

Hi guys,
this is my first post here. I am stuck up with finding smallest and
highest value (int) of array. I have two problems, first is that in
second loop where I start to loop for smallest and highest value I never
get "0" pass, and because of that I never compare index 0- first element
of array. Loop is starting at second element off array.
Second problem is that comparison is not working. If I enter numbers
in order like 1,2,3,4... I got correct comparison, but if I put unordered
nuumbers like 23,1,45,3,67... I got "wild matches" here is echo from
console:
1 pass**** 67 value of highest: 67
2 pass**** 2 value of smallest: 2
3 pass**** 11 value of highest: 11
4 pass**** 67 value of highest: 67
5 pass**** 245 value of highest: 245
6 pass**** 17 value of highest: 17
7 pass**** 55 value of highest: 55
8 pass**** 23 value of highest: 23
9 pass**** 4 value of highest: 4
highest entry is: 4 smallest entry is: 2

You can also see that there is no = pass which is first element of array.
Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  #include <iostream>

using namespace std;

int main()
{
	int input;
	int array[10];
	for (int i = 0; i < 10; i++)
	{
		cout << "Please enter 10 numbers:" << '\n';
		cin >> input;
		array[i] = input;
	}
	int ref_max = array[0];
	int ref_min = array[0];
	int highest = 0;
    int smallest = 0;
	cout << array[0] << '\n';
	for (int z = 0; z < 10; z++)
    {
        if (array[z] > ref_max)
        {
            highest = array[z];
            cout << z << " pass**** " << array[z] << " value of highest: " << highest <<'\n';
        }
        else if (array[z] < ref_min)
        {
            smallest = array[z];
		    cout << z << " pass**** " << array[z] << " value of smallest: " << smallest <<'\n';
        }
    }
		cout << "highest entry is: " << highest << " smallest entry is: " << smallest << '\n';
}


Thx!
Problem is that ref_max never changes if (array[z] > ref_max) Better to compare it with highest. Same with ref_min.

Here is an example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>

using namespace std;

int main ()
{
  int input;
  int array[10] = {10,9,8,7,6,5,4,3,2,1};

  int highest = array[0];
  int smallest = array[0];

  for (int z = 0; z < 10; z++)
  {
    if (array[z] > highest)
    {
      highest = array[z];
      cout << z << " pass**** " << array[z] << " value of highest: " << highest << '\n';
    }
    if (array[z] < smallest)
    {
      smallest = array[z];
      cout << z << " pass**** " << array[z] << " value of smallest: " << smallest << '\n';
    }
  }
  cout << "highest entry is: " << highest << " smallest entry is: " << smallest << '\n';

  system ("pause");
}
Thx Thomas!
It is working, and also my confusion with 0-pass of loop is also working,
thx again! ;)
Topic archived. No new replies allowed.