A few comments/suggestions:
1)
Your
pancake array is big enough to hold 5 numbers, but you're only using 4 of them
1 2 3
|
for (z = 1;z < 5;z++) {
for (i = 1;i < 5;i++)
|
Arrays start from index zero, but at the moment, your
for loops all begin at 1, so you're missing out on your first (Zero'th) element.
2)
Many C++ programmers follow a principle known as "declare on first use" - which simply means waiting to declare/define variables until they're actually needed - this can be a good habit to get in to. instead of having a big lump of variables all declared at the top main, you can create them at the same time as they're first needed. e.g.
1 2 3
|
for (int z = 0;z < 5;z++) {
for (int i = 0;i < 5;i++)
|
Doing this limits the scope of 'i' and 'z' to the block of code where they're needed and nowhere else - this reduces the chance that you might slip up somewhere else by using 'i' or 'z' for something which you didn't intend (mistakes are very easy to make, especially in more complicated code when you've perhaps got a lot of variables)
3)
Try to be consistent with your placement of braces - consistent code is easier to read for everyone. Some people prefer to align them horizontally, other people prefer to put them at the end of the previous line. It doesn't matter "style" you prefer (and the style you choose is a personal preference), just so long as you stick to it
- As for putting your
pancake array into order, you could either write your own sorting code (Have a google search for
bubble sort and
selection sort ) or you can use the quick-and-easy way which C++ provides for you out-the-box, called 'sort'. (I'd suggest you try out both bubble sort and selection sort though)
#include <algorithm> // Contains useful tools for handling arrays and other sets of data
...
1 2 3 4 5 6 7 8
|
int pancake[5];
for (int i = 0;i < 5;i++) {
cout << "how many pancakes did person " << i << " eat?" << endl;
cin >> pancake[i];
}
sort( pancake, pancake+5 );
|
Don't be put-off by the 'pancake+5' -
sort needs to know the start and end of
pancake in order to sort it. in plain english,
pancake+5
translates into
"after 5 elements of the pancake array"
(Side Note: the
+
uses a mechanism called
pointer arithmetic - but you don't need to worry about that for now.)