Help with % and switch case

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));
    }

Is that true you can't use math to state a case

It's true. Case values must be constants.

However, if you are using %5, remainder will have a constant value of 0, 1, 2, 3, or 4. You could do this:

switch(remainder)
{
   case 0:
   case 1:
   case 2:
     // remainder is less than 3. Do something
     break;
   case 3:
   case 4:
     // remainder is 3 or more Do something else
     break;
}

This code:

    if (remainder > 5 && remainder < 8){
      newNum = (original - (remainder - 5));
    }
    if (remainder > 7){
      newNum = (original + (10 - remainder));
    }

Neither of these blocks will be true, ever. Remainder is never larger than 4.

Thanks for clarifying that Cases must use constants. I was going nutty trying all different kinds of syntax to make it work.

...and I redid my basic math, seeing as you are correct, the % will never be greater than 4.

That cleaned things up a bit. I appreciate it!