Random If statement returns!

Hey everyone!

My code to a specific function is below.
As a foreword: The goal is very simple.
tile, which is a global integer that is assigned from a rand() (in another function)
is then taken to this function, where it is put up against multiple if statements. Since tile is a single integer, it SHOULD only be possible for one of these statements to be true.

Not the case.

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
int tileEvent(){
    cout << tile << endl;
    if (tile == 0||2||4||6||8||10||12||14||16||18||20||22){
        cout << "You landed on Opportunity!" << endl;
        drawOpportunityCard();                         
    }
    if (tile == 1||9||17){
        cout << "You landed on Doodads!" << endl;
        drawDoodadsCard();
    }
    if (tile == 3){
        cout << "You landed on Charity!" << endl;
        drawCharityCard();
    }
    if (tile == 5||13||21){
        cout << "You landed on Pay Check!" << endl;
        drawPayCheckCard();
    }
    if (tile == 7||15||23){
        cout << "You landed on Market!" << endl;
        drawMarketCard();
    }
    if (tile == 11){
        cout << "You landed on Baby!" << endl;
        drawBabyCard();
    }
    if (tile == 19){
        cout << "You landed on Downsized!" << endl;
        drawDownsizedCard();
    }
    else {
        cout << "There was an error with tile placement." << endl;
    }


When this code is executed, tile is cout'd and may be a variety of numbers, but no matter what number it is, it somehow causes most of the functions to pass true...

so my output is

2
You landed on Opportunity!
You drew an Opportunity card
You landed on Doodads!
You drew a Doodads card
You landed on Pay Check!
You drew a Pay Check card
You landed on Market!
You drew a Market card
There was an error with tile placement.


I am using an online ide, but I doubt that is relevant.

I don't know what else needs to be said, since this is painfully simple. I am using C++11 and I am 98% sure other functions are not interfering.
Take for instance line 15. The correct way to write this would be:
if (tile == 5 || tile == 13 || tile == 21){

I would instead suggest turning this into a switch statement.
Wow thanks! I knew it would be something simple...

On a side note, is there any benefit from using a switch statement other than simplicity? Do switch statements acts identically to a series of else if statements?
Switch statements are easier for the compiler to optimize and can sometimes be easier to read.
Aside from that, switch statements only work with integral types.
Gotcha. Thanks for the information and hastiness! Much appreciated.
Topic archived. No new replies allowed.