what I have is a program that takes in 3 numbers (feet, inches, sixteenths) then multiplies them by x. Upon starting to write the output part, I ran into needing:
if (sixteenths4<16) {
sixteenths5=sixteenths4;
inches6=0;
}else if (16<=sixteenths4) {
sixteenths5=sixteenths4-16;
inches6=1;
}else if (32<=sixteenths4) {
sixteenths5=sixteenths4-32;
inches6=2;
}else if (48<=sixteenths4) {
sixteenths5=sixteenths4-48;
inches6=3;
} else {
sixteenths5=sixteenths4-64;
inches6=4;
}
I realize the last else is redundant as it will never happen. Since the total sixteenths could exceed 4-5 hundred, that would be a lot of if else's; my question is, would there be a better way to do this?
Aucun commentaire:
Enregistrer un commentaire