Pancake Glutton- Glitchy coding?

Hey. I'm trying to write a practice program that takes 10 numbers of the number of pancakes a person eats. The program works up until the output of the min and max numbers. It will output the following


 
The skinniest person here is person #0 from eating only 10 pancakes! 


every time...

Here's the code. I created a 2x10 array. 1 row containing the persons number and the other containing the number of pancakes. the way the HighEater and LowEater functions are supposed to work is that they traverse the array. If the current coor.'s value is greater/lesser than the min/max, it will assign the Max/Min value whatever the current number is...

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
48
49
50
51
52
53
54
55
#include <iostream>
using namespace std;

int xEnd = 10;
int pancakes[2][10];

void HighEater();
// Finds the biggest glutton

void LowEater();
// Finds who ate the least.

void Test();
//tests the array

int main()
{
    for (int i = 0; i++ < xEnd;) pancakes[0][i]=i; //sets up array row 1
    cout << please enter the amount of pancakes ten people ate individually!"\n";
    for (int i = 0; i++< xEnd;) {
        cin >> pancakes[1][i]; // sets up array row 2
    }
    HighEater();
    LowEater();

    return 0;
}

void Test() {
    for (int y = 0; y < 2;y++) {
        for (int x = 0; x++ < xEnd;)
            cout << pancakes[y][x] << "\t";
        cout << "\n";
    }
}

void HighEater()
{
    int MAX = 0;

    for (int i = 0; i < xEnd; i++) {
        if (pancakes[1][i] > pancakes[1][MAX]) MAX = pancakes[0][i];
    }
    cout << "The biggest glutton in the group is person #" << pancakes[0][MAX] << " with "<< pancakes[1][MAX]<< " pancakes!"<<endl;
}

void LowEater() {
   int MIN = pancakes[0][0];

    for (int i = 0; i < xEnd; i++) {
        if (pancakes[1][i] <=pancakes[1][MIN])
            MIN = pancakes[0][i];
    }
    cout << "The skinniest person here is person #" << pancakes[0][MIN] << " from eating only "<< pancakes[1][MIN]<< " pancakes!"<<endl;
}


Any input is appreciated :)
Last edited on
You've got a logic error. MAX is either the maxim value, or the index of the maxim value.
1
2
MAX = pancakes[i]; //MAX used as a value
pancakes[MAX]; //MAX used as index 

Also, if you're going to name the persons form 0 to n-1, just use the index of the array (no need the extra row)
Topic archived. No new replies allowed.