Pancake Glutton

Hi i have a question about my code here.
its suppose to be the solution to
Pancake Glutton

Write a program that asks the user to enter the number of pancakes eaten for breakfast by 10 different people (Person 1, Person 2, ..., Person 10)
Once the data has been entered the program must analyze the data and output which person ate the most pancakes for breakfast.

★ Modify the program so that it also outputs which person ate the least number of pancakes for breakfast.

Problem is, when the most or least person that ate cakes are the person #1 or 2, it cannot process it instead it only counts the results from person #3, #4, #5.
can someone point out whereabout my mistake 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
#include <iostream>

using namespace std;
int main ()

{
    int index;
    int most=0;
    int person[5];
    int least=0;
    int totalMax =0;
    int totalMin = 0;
    for (index = 0; index < 5; index++) {
        cout << "Enter how many person #" << index +1<< " ate.";
        cin >> person[index];
        cout << "person #" << index+1 << " ate " << person[index] << " cakes"<< endl;
    if (person[index] > person[index - 1]) {
        most = index;
        totalMax = person[index];
        }
    if (person[index] < person[index-1]) {
        least = index;
        totalMin = person[index];
        }
    }
    cout << "person #" << most +1<< " ate most of the cake with total of " << totalMax << endl;
    cout << "person #" << least+1 << " ate least of the cake with total of " << totalMin << endl;
    return (0);
}
Topic archived. No new replies allowed.