```
void putTile(int &n1, int &n2, int &n3, int &n4, int &n5, int &n6, int &n7, int &n8, int &n9)
{
    srand(time(0));
    int i = (((rand()%10)) < 5 ? 2:4);

    if (n1||n2||n3||n4||n5||n6||n7||n8||n9 == 0) {
        switch((rand()%9) + 1) {
        case 1:
            n1 = i;
            break;
        case 2:
            n2 = i;
            break;
        case 3:
            n3 = i;
            break;
        case 4:
            n4 = i;
            break;
        case 5:
            n5 = i;
            break;
        case 6:
            n6 = i;
            break;
        case 7:
            n7 = i;
            break;
        case 8:
            n8 = i;
            break;
        case 9:
            n9 = i;
            break;
        }
    }
}

```

I am trying to generate either 2 or 4 at empty places(places containing 0) randomly, but my algorithm inputs randomly generated numbers (2 or 4) at random places even at places having a number already, as I have used the if statement at the beginning of the code. Any suggestions on how to correct the code?