Question: I'm writing a program which should scan 4 variables N-times (1var - Name, 2var - lastName, 3var - grade, 4 var - score) and print name and last name of man, who have highest score. If we have more than 1 winner, it's prints amount of winners.

I have an algorithm which finds the highest score, but I can't find a solution to the name and the name inscribed on the new variable at a time, when suddenly the next person will be the winner.

How can I do this?

I tried to create a two-dimensional array of rows and exchange in the loop, but nothing happened. All output time only program garbage.

Here's a fragment of my code, I marked problem area with comment:

```
int N, score, grade, amount, k, bestscore;
scanf("%d", &N);
char fname[20], sname[20];
bestscore=0;
 amount=1;
    for(int i=0; i<N; i++)
             {
              scanf("%s %s %d %d", fname, sname, &grade, &score);
              if (score<200)
                      {
                        if (score !=0 && score==bestscore)
                             {
                              amount++;
                             }
                        if (score>bestscore)
                             {
                              //something that solve problem
                             }
                      }
             }
if (amount>1)
   {
   printf("%d", amount);
   }
else printf(%s %s", fname, sname);

```

Answer: 
You're calling the function instead of assigning it.

```
getElementById(cbox[i].id).onclick = Mclick;

```

Of course, now your function will receive an event argument instead of an id. (Passing the id inside the loop is a huge pain; easiest fix is to not bother trying.) But it also gets the attached element as `this`, which is convenient:

```
function Mclick() {
    alert(this.id);
}

```

Other comments:

1. You should try not to be in the habit of using `innerHTML` if you're not assigning a string that contains known HTML. Saves you from having to care about escaping. Use `textContent` instead.
2. Assigning to `onclick` is a bit inflexible; you can only ever assign one click handler this way, and it's hard to notice if you accidentally overwrote an existing handler. Use [`addEventListener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener).
3. `getElementById(element.id)` should surely be equivalent to `element`.
4. Don't use HTML comments within JavaScript! :) They only work for... weird backwards-compatibility reasons. JavaScript comments are either `// ...` or `/* ... */`.
5. Best not to capitalize a function name unless it's supposed to be a constructor; you may notice that SO's highlighting made `Mclick` green, because it thinks it's a class name.

So I'd end up with:

```
function initnav() {
    var cbox = document.getElementsByClassName('box');
    for(var i = 0; i < cbox.length; i++) {
        cbox[i].textContent = cbox[i].id;
        cbox[i].addEventListener('click', alert_id);
    }
}

function alert_id(event) {
    alert(this.id);
}

```
So basically you don't call the for loop since the for loop is in the function. If you want to call all your variables and the statements in the for loop you have put the statements in the function and call the function outside of the function but inside of the script.