Code: Select all
if(home.longi >= 0 && home.longi < 7.5) {
home.zone = 0;
}
if(home.longi >= 7.5 && home.longi < 22.5) {
home.zone = 1;
}
if(home.longi >= 22.5 && home.longi < 37.5) {
home.zone = 2;
}
if(home.longi >= 37.5 && home.longi < 52.5) {
home.zone = 3;
}
if(home.longi >= 52.5 && home.longi < 67.5) {
home.zone = 4;
}
if(home.longi >= 67.5 && home.longi < 82.5) {
home.zone = 5;
}
if(home.longi >= 82.5 && home.longi < 97.5) {
home.zone = 6;
}
if(home.longi >= 97.5 && home.longi < 112.5) {
home.zone = 7;
}
if(home.longi >= 112.5 && home.longi < 127.5) {
home.zone = 8;
}
if(home.longi >= 127.5 && home.longi < 142.5) {
home.zone = 9;
}
if(home.longi >= 142.5 && home.longi < 157.5) {
home.zone = 10;
}
if(home.longi >= 157.5 && home.longi < 172.5) {
home.zone = 11;
}
if(home.longi >= 172.5) {
home.zone = 12;
}
Now I've come to the conclusion that the easiest way out is checking if a given value, inputted by the user (here stored in home.longi) is positioned between two set values. If it isn't, it should go on to the next two values, check if it's positioned there, etc. I tried some more tricks for it (thought I came to a solution using an array and a for-loop, but that seems to be completely the wrong way as well), so this's the only working code I managed to make. I know there must be an easier way to get this done, without all those ifs, but can't find it.
So, my question is: how can I improve this code so that it won't be so long and still do the same?
Thanks.
Edit: Forgot to say this: it should do it with target.longi on target.zone too, if that might help.