My goal is to read a pot rounded to the nearest 5. (So as you turn it, it counts 5, 10, 15, 20 etc...) The following code works, but it just seems like a long way to go for the result. Any alternative methods are appreciated.
I also tried using a switch case to get rid of the "If" statements, but it seems the cases won't accept an equation like this:
switch(var) {
case (<3): // <---Doesn't compile
//do something here
Is that true you can't use math to state a case, or am I just doing it wrong?
Here's the code I use to get the numbers rounded to the nearest 5. It works with the rest of the program, but I feel like there's a neater way to do this.
remainder = (original % 5);
if (remainder < 3){
newNum = (original - remainder);
}
if (remainder > 2 && remainder < 6){
newNum = (original + (5 - remainder));
}
if (remainder > 5 && remainder < 8){
newNum = (original - (remainder - 5));
}
if (remainder > 7){
newNum = (original + (10 - remainder));
}