How can I convert an if..else if..else statement to a single formula I have this program where I made a variable x, and I want to assign it a value based on this formula (where c is a positive integer):
$$
x = f(c) = 
\begin{cases}
c & c<100\\100 & 100<=c<200\\c-100 & c>=200
\end{cases}
$$
At the moment I have this in some code using an if statement, but I'd like to have this using a single assignment with just a formula and no if statements.
  int x;
  if (c < 100) 
    x = c;
  else if (c < 200)
    x = 100;
  else
    x = c-100;

I've heard that if statements like this can be converted into some formula, but I'm not sure where to start, any help would be appreciated!
In the end, I'll hopefully have just one statement:
int x = f(c);


You could use:
$$f(c) = c-50+\frac{|c-200|-|c-100|}{2}$$
Wolfram Alpha
