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!
#include <iostream>
usingnamespace 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.";
}
elseif (two > one && two > three && two > four && two > five)
{
cout << "Jill ate the most.";
}
elseif (three > one && three > two && three > four && three > five)
{
cout << "Jake ate the most.";
}
elseif (four > one && four > two && four > three && four > five)
{
cout << "Jim ate the most.";
}
elseif (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.