what am i doing wrong

Hello I have an issue, I am writing a program where I am trying to find out who ate the most pancakes. And I don't know what I am doing wrong, can you tell me what I can do to fix my code. I only wrote down two if/else statements because I wanted to make sure I was doing it correctly before doing the same thing to every problem.

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
56
57
58
 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.

 ★★★★ Modify the program so that it outputs a list in order of number of pancakes eaten of all 10 people.
 i.e.
 Person 4: ate 10 pancakes
 Person 3: ate 7 pancakes
 Person 8: ate 4 pancakes
 ...
 Person 5: ate 0 pancakes

*/#include <iostream>

using namespace std;

int main()
{


//variables
int person1=0;
int person2=0;
int person3=0;
int person4=0;
int person5=0;
int person6=0;
int person7=0;
int person8=0;
int person9=0;
int person10=0;
//output message
 cout<<"Enter the number of pancakes eaten by 10 different people."<<endl;

//create a list of the people
cin>>person1;
cin>>person2;
cin>>person3;
cin>>person4;
cin>>person5;
cin>>person6;
cin>>person7;
cin>>person8;
cin>>person9;
cin>>person10;

//make program analyze the data and output who ate the most pancakes
    if(person1>person2&&person3&&person4&&person5&&person6&&person7&&person8&&person9&&person10)
    {
    cout<<"Person 1 ate the most pancakes."<<endl;
    }
        else if (person2>person1&&person3&&person4&&person5&&person6&&person7&&person8&&person9&&person10);
        {
        cout<<"Person 2 ate the most pancakes."<<endl;
        }

return 0;
}
In case you're still having trouble, I went ahead and tested it out.

input :
10 9 8 7 6 5 4 3 2 1 

output: 
Person 1 ate the most pancakes.
Person 2 ate the most pancakes.


It's your semi-colon after your
1
2
3
4
else if (person2>person3&&...&&person10); // <--- this needs to go
 {
        cout<<"Person 2 ate the most pancakes."<<endl;
        }
statement.

Just get rid of the semi-colon and it'll work. See:
Enter the number of pancakes eaten by 10 different people.
Person 1 ate the most pancakes.


http://ideone.com/1UQn7x

You don't have to loop back person1, into your second else if, it should decrease since you already know for sure person 1 isn't greater than either 2,3,...10.
Last edited on
If you think that ten is bad, then prepare for the 200 person pancake party that you'll arrange any time soon ...

In other words, there is a better way that is called "array". Look at this example: http://www.cplusplus.com/reference/array/array/operator%5B%5D/
Thanks @BarelyOtaku
It is insane how precise you have to be with the syntax but I am learning.


@keskiverto
I didn't know we could store lots of values in one variable, I will look into this more thanks.
Topic archived. No new replies allowed.