Feedback and advice wanted :)

Okay I just wrote a program that asks the user to enter 5 separate numbers to correspond to the amount of pancakes that five people ate. Then the console says who ate the most. I just wanted feedback as to whether I wrote this in the most efficient way and whether anyone suggests that I do something different, maybe if i overcomplicated it. Thanks!

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
#include <iostream>

using namespace std;

int main()
{
    int one, two, three, four, five;
    cout << "Jack, Jill, Jake, Jim, and Jason ate pancakes for breakfast. \nList five numbers representing what amount of pancakes each person ate:" << endl;
    cin >> one;
    cin >> two;
    cin >> three;
    cin >> four;
    cin >> five;
    if (one > two && one > three && one > four && one > five)
    {
        cout << "Jack ate the most.";
    }
    else if (two > one && two > three && two > four && two > five)
    {
        cout << "Jill ate the most.";
    }
    else if (three > one && three > two && three > four && three > five)
    {
        cout << "Jake ate the most.";
    }
    else if (four > one && four > two && four > three && four > five)
    {
        cout << "Jim ate the most.";
    }

    else if (five > one && five > two && five > three && five > four)
    {
        cout << "Jason ate the most.";
    }
    return 0;
}
What would happen if the highest was a tie between two people? Your program doesn't handle that.

I think that instead of having a bunch of variables named after numbers, you could employ an array so that you can easily change the size. Then you can use a loop to read in the data instead of a bunch of individual lines.
Topic archived. No new replies allowed.