Arrays

How would I find and display the largest and the smallest values stored in an array?
1. Your array should contain only elements of the same (or some derived) type.
2. There should be a totally order defined on those type of elements.
3. If your array is of one only dimension searching it for the largest and smallest element in a simple loop shouldn't be as difficult. Or did I misunderstand your question?
What function finds or returns the largest and smallest value in an array?
Have a look at http://www.cplusplus.com/reference/algorithm/. You may find your answer there.
Before the loop begins, set both the max and min to the value of the first array element. Use a loop and the < or > operator as appropriate, to test each value, and replace the current max or min as required.
This is what I have so far.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int a[10];
int main()

{
	while ( a != 10);
	{
	cout << "Please enter a value for the variable a" << endl;
	cin >> a;
	}
	
This won't compile. Please compile first. Then try fixing your errors/warnings. Then lets have a look at the resulting code.
Topic archived. No new replies allowed.