stm
YaBB Newbies
Offline
Posts: 8
switch statements?
Nov 4th , 2009, 10:52am
I've been working on a typography clock, and everything has been going well until i discovered "8:00" is displayed as "eight o'clock eight" which is wrong... obviously its gone well using just if statements, but the problem is it doesnt stop after. is there a way to stop it from displaying the hour after. Or do i really have to resort to switches? Ive been trying to get those to work but its not been very sucessful. [im still pretty new to this programming lang] this is what it is at the moment... PFont myfont; void setup() { size (900,90); background(100,100,100); smooth(); myfont = loadFont("Garamond-Bold-48.vlw"); textFont(myfont); } void draw() { background(242,239,220); int s = second(); int m = minute(); int h = hour(); //text(h+":"m":"+s, 15, 50); textSize(60); fill(36,36,36); //------------------add minute in text------------------ if((m > 4) && (m <= 9)){ text("five past " , 25, 60);} if((m > 9) && (m <= 14)){ text("ten past ", 25, 60);} if((m > 14) && (m <= 19)){ text("quarter past ", 25, 60);} if((m > 19) && (m <= 24)){ text("twenty past " , 25, 60);} if((m > 24) && (m <= 29)){ text("twenty five past " , 25, 60);} if((m > 29) && (m <= 34)){ text("half past " , 25, 60);} if((m > 34) && (m <= 39)){ text("twenty five to " , 25, 60);} if((m > 39) && (m <= 44)){ text("twenty to " , 25, 60);} if((m > 44) && (m <= 49)){ text("quarter to " , 25, 60);} if((m > 49) && (m <= 54)){ text("ten to " , 25, 60);} if((m > 54) && (m <= 59)){ text("five to " , 25, 60);} //------------------add hour in text------------------ if((h == 12) || (h == 00)){ text("twelve");} if((h == 11) || (h == 23)){ text("eleven");} if((h == 10) || (h == 22)){ text("ten");} if((h == 9) || (h == 21)){ text("nine");} if((h == 8) || (h == 20)){ text("eight");} if((h == 7) || (h == 19)){ text("seven");} if((h == 6) || (h == 18)){ text("six");} if((h == 5) || (h == 17)){ text("five");} if((h == 4) || (h == 16)){ text("four");} if((h == 3) || (h == 15)){ text("three");} if((h == 2) || (h == 14)){ text("two");} if((h == 1) || (h == 13)){ text("one");} //------------------add -ish in text------------------ if((m > 5) && (m <= 9)){ text(" -ish" );} if((m > 10) && (m <= 14)){ text("-ish" );} if((m > 15) && (m <= 19)){ text("-ish" );} if((m > 20) && (m <= 24)){ text("-ish" );} if((m > 25) && (m <= 29)){ text("-ish" );} if((m > 31) && (m <= 34)){ text("-ish" );} if((m > 35) && (m <= 39)){ text("-ish" );} if((m > 40) && (m <= 44)){ text("-ish" );} if((m > 45) && (m <= 49)){ text("-ish" );} if((m > 50) && (m <= 54)){ text("-ish" );} if((m > 55) && (m <= 59)){ text("-ish" );} if((m > 0) && (m <= 4)){ text("-ish" );} //------------------add o'clock and others in text------------------ if((h==00) && (m <= 4)) text("midnight", 25, 60); if((h==12) && (m <= 4)) text("afternoon", 25, 60); if((h==11) && (m <= 4)) text("elven o'clock", 25, 60); if((h==10) && (m <= 4)) text("ten o'clock", 25, 60); if((h==9) && (m <= 4)) text("nine o'clock", 25, 60); if((h==8) && (m <= 4)) text("eight o'clock", 15, 60); if((h==7) && (m <= 4)) text("seven o'clock", 25, 60); if((h==6) && (m <= 4)) text("six o'clock", 25, 60); if((h==5) && (m <= 4)) text("five o'clock", 25, 60); if((h==4) && (m <= 4)) text("four o'clock", 25, 60); if((h==3) && (m <= 4)) text("three o'clock", 25, 60); if((h==2) && (m <= 4)) text("two o'clock", 25, 60); if((h==1) && (m <= 4)) text("one o'clock", 25, 60); } thanks