CPP homework (need to realize what this does)

My teacher wrote a code for us to determine what it does line by line. I skipped some intro parts which are library, main. Here is the code;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int array[5]={7,3,5,10,3},i,big, secondbig;
    if(array[0]>array[1]){
        big=0;
        secondbig=1;
        }
    else
        {
        big=1;
        secondbig=0;
    }
    for(i=2;i<5;i++){
        if(array[big]<array[i]){
                secondbig=big;
                big=i;
                continue;
            }
        if(array[secondbig]<array[i]){
                secondbig=i;
        }

I can determine until 17th line. Speacially, why it works if we cut out 17th to 19th line. If you have any time, and willing to help me, I'd be appreciated, and you would help me to understand it. I'm kinda beginner to CPP. And don't want to get C from teacher's quiz.

Thank you,
Badcode
Last edited on
Do you know what the general purpose of the for loop is?
I think so, yes. But haven't got any idea about 17th to 19th line. Why does code work if we cut out those parts.
closed account (D80DSL3A)
Why does code work if we cut out those parts.

Because coincidence leads to the same result.

Try removing lines 17-19 and change the 10 in the array to a 1.
I think you will find that arr[big] = 7 (correct) and arr[secondbig] = 3 (wrong, should be 5).
Thank you, that was really helpful.
Topic archived. No new replies allowed.