Identifying numbers in arrays.

I have created a program which takes in the user input for a couple of things and sorts them out in an array. The problem is, I would like to print the highest and lowest numbers in the array.

Here's 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
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

int compare(const void * a, const void * b)
{
	return( *(int *)a - *(int*)b );
}


int main()
{
	std::cout << "Pancakes!\n\n\n Free pancakes for the first 20 people\n\n\n" << std::endl;

	int cakearr[10];

	for(int a = 0;a < 10; a++)
	{
		
		
		std::cout << "How many pancakes would you like, person " << a << " ? ";
		
		std::cin >> cakearr[a];
		
		
		
	}

	std::cout << "\n";

	qsort(cakearr, 10,sizeof(int), compare);
	for(int x = 0; x < 10; x++)
	{
		std::cout << "Person " << x << " had " << cakearr[x] << " pancake(s).\n\n";
	}

	



	std::cin.get();
	char f;
	std::cout << "\n\nEnter a number to terminate the program: ";
	std::cin >> f;
	return 0;
}


I have been wondering how to go about this for a while now. Could anyone give me any hints?
I don't really know what you want to do in this program.
This program prints the highest and the lowest elements from an array:

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>
#define CONSTANT 1000000L  //this is a constant (it's value is higher than an integer value (32767)
using namespace std;
int v[100], i, highest=0, lowest=0, n;
int main()
{
             cout<<"The length of the array is: ";
             cin>>n;
             for(i=1; i<=n; i++)
             {     cout<<"v["<<i<<"]=";
                    cin>>v[i];
             }
             highest=v[1];
             lowest=CONSTANT;
             for(i=1; i<=n; i++)   //the loop which performs the conditions
             {
                 if(highest<v[i])   //condition #1
                 {
                     highest=v[i];
                 }
                 if(lowest>v[i])   //condition #2
                 {
                     lowest=v[i];
                 }
             }
             cout<<"The highest element in that array is: "<<highest<<"\n";
             cout<<"The lowest element in that array is: "<<lowest;
             return (0);
}
Topic archived. No new replies allowed.