This program has been done many times, so do a search here and you can find similar code that has been worked out to look at.
Some suggestions:
Put line 7 inside of main and pass what variables that are needed to the functions. Better to stay away from global variables if at all possible.
"main" is missing the "return 0;" before the closing brace.
"clrscr()" may work for you right now, but it does not work for everyone.
In the sort function since "pan" and "p" would e considered parallel arrays you need to sort both at the same time.
You should create function for lest and most pancakes eaten. These functions could either display the results or return an index number for later use.
The programs I have worked on in the past kept track of names and amounts.
For testing purposes you can comment likes 15 - 20 and initialize you variables and arrays with the information you need so that you do not have to type in information every time the program runs and the arrays can be larger this way.
"main" is missing the "return 0;" before the closing brace.
This is not necessary.
The body of the main function does not need to contain the return statement: if control reaches the end of main without encountering a return statement, the effect is that of executing return 0;.
Initial problems I found before I could even run the program.
There is no file "iostream.h" or "iomanip.h" just "iostream" and "iomanip".
Changed "sort();" to "void sort(int pan[], int p[]);". it was missing the return type an after moving line 7 to inside main the arrays need to be passed to the function. Also had to change the function definition.
Things like "cout",, "cin" and "endl" needed to be qualified with "std::" to work.
Needed to define "temp" inside the "sort" function.
Temp defined in main is not used.
In your for loops you should declare the type of the variable when defined in the first part. If you do this outside the for loop it works, but easy to loose track of what you did ending up with a variable that is used, but not defined. In the last for loop of "sort" "a" did not have a type,"int", and the array "p" used a subscript of "i" which was never defined anywhere i the function.
To find the least/most, it's usually better to keep track of the index of the smallest/largest value. That way if you need the index, you have it:
1 2 3 4 5 6 7 8 9
most = 0;
if (pan[1] > pan[most]) {
most = 1;
}
if (pan[2] > pan[most]) {
most = 2;
}
cout << "\nWho ate the most pancake? Person " << most+1 << " ate " << pan[most] << '\n';
Those if statements will get too cumbersome if the array is larger, and it will be downright impossible if you don't know exactly how many entries there are, so it's more common to do it inside a loop:
1 2 3 4 5 6
most = 0;
for (i=1; i<3; ++i) {
if (pan[i] > pan[most]) {
most = i;
}
}
If the number of items changes, you just change the upper bould (3 in this case).
It's more advanced, but there are actually functions in the standard library to find the smallest and largest items in a collection (max_element() and min_element())
The more I look at your program the more I feel that you are not following the instructions correctly.
The if/else if statements may work for now, but what would you have to do if the array size is 50? Both of these would work better in their own functions using a for loop to step through the array to find the min and max and return the index of min or max.
I noticed in the sort function the outer for loop has the condition x <= 5, but the arrays only hold three elements. This will be a problem if it works. If you set up the sort routine differently you could make use of both "x" and "a".
Hope that helps,
Andy
P.S. The use of the global variables may work, but it is not the best way to program. They should be defined in main and passed to functions that need them.