You should have written if(tower_height>=0 && tower_height<=23) { //body } but if u write if(statement); { //body } this is a logical error . The body of if statement will run for sure irrespective of the if statement. your code can also be interpreted as: if(statement) { } //body