It is simple...
Code:void hourSpot1(){
if ((h == 10) || (h==11) || (h==12) || (h==22) || (h==23) || (h==24)){
num1();
} else {
num0();
}
}
I see a little inefficiency in your code, for hourSpot2(), which is slow (although it doesn't really matter here, to be honest) because you shouldn't test h after finding a value (if it is 2 it won't be 13) - this can be addressed by adding else before each if (except the first, of course!).
But still, it isn't very readable and hard to maintain (proof: 24 is tested twice!
).
I suggest you use the switch construct, perfect for these cases:
Code:switch (h) {
case 1:
case 11:
case 13:
case 23:
num1();
break;
case 2:
case 12:
case 14:
case 24:
num2();
break;
case 3:
case 15:
num3();
break;
case 4:
case 16:
num4();
break;
case 5:
case 17:
num5();
break;
case 6:
case 18:
num6();
break;
case 7:
case 19:
num7();
break;
case 8:
case 20:
num8();
break;
case 9:
case 21:
num9();
break;
case 10:
case 22:
num0();
break;
}
Both faster than cascaded ifs, particularly your form (switch jumps directly at the right case) and easier to understand (and smaller).
Exercice: handle option for 24hrs display (I am used to that!). :-D