HELP ME WITH DISTINCT VALUES

Hello! Help me with this one! My professor wants me to create a program that allows user to enter 5 distinct ages of family members and display the youngest and oldest age. I can't seem to do the distinct part. Help me with this! I have started doing it already.

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
  #include <iostream>
using namespace std;
const int num = 5;

int minVal, maxVal;
int a[num];
int main ()
{
	cout << "Enter 5 distinct ages of family members\n\n";
	for (int i=0; i<5; i++)
	{
	cout << "Enter age " << i+1 << ": ";
	cin >> a[i]; 
	}
	minVal = a[0];
	maxVal = a[0];
		for ( int i=1; i<num; i++)
		{
			if (minVal > a[i])
			{
			minVal = a[i];
			}
			else if (maxVal < a[i])
			{
			maxVal = a[i];
			}
		}
	cout << "The youngest age is: " << minVal << endl;
	cout << "The oldest age is: " << maxVal << endl;
	return 0;
}


THE OUTPUT SHOULD BE SOMETHING LIKE THIS:

Enter age 1: 17
Enter age 2: 17
Age already exists!
Enter age 2: 16
Enter age 3: 43
Enter age 4: 16
Age already exists!
Enter age 4: 61
Enter age 5: 4

Youngest age: 4
Oldest age: 61
Last edited on
Topic archived. No new replies allowed.