Pancake Glutton Hit and Miss Program

I made this for the Pancake Glutton exercise and although it does work, it seems to be hit and miss. If anyone has any idea why I'd be glad to know. I would like to keep it in the realm of basic technique though.

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
//Pancake Glutton
#include <iostream>

int main()
{
    using namespace std;
    
    int pmax, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, i;
    int NumberOfPancakes[1][10] = {p1, p2, p3, p4, p5, p6, p7, p8, p9, p10};
    int MaxPancakes[1][1] = {pmax};
    int j = 1, k = 0;
           
    for (i = 1; i < 11; i++)
    {
        cout << "How many Pancakes did person " << i << " eat?\n";
        cout << "Number of Pancakes: ";
        cin >> NumberOfPancakes[0][i];
        cout << endl;
    }      
          
    for (i = 0; i < 11; i++)
    {
        if (NumberOfPancakes[0][i] > NumberOfPancakes[0][j])
        {
           pmax = NumberOfPancakes[0][i];
           k = i;
           j++;
        }
    }
    
    cout << "The max number of pancakes eaten was " << pmax << ".\n";
    cout << "The " << pmax << " pancakes were eaten by person number " << k << ".\n";
       
    char response;
    cin >> response;
    return 0;
}    


Thanks in advance.
Last edited on
Why do you have a two-dimensional array there? You could do with just one... anyways.

When checking, input k as the argument in place of j. In fact, j is redundant.

-Albatross
You mean as in:
int NumberOfPancakes[1][10] = {p1, p2, p3, p4, p5, p6, p7, p8, p9, p10};

Because if I switch it to [0][10] I get this error:
"excess elements in aggregate initializer".

Also, is there anything actually wrong with it? Sometimes a number that is bigger (but still in range of int) is ignored. Maybe I just inputted the numbers wrong though.


Topic archived. No new replies allowed.