Workaround using switch case

I am having a switch case, in which should trigger on a value.. The idea was that when the double lies in between a certain range, a certain case should be executed.. It looks like that switch only takes int as input..

How can i do this??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  for(int i = 0 ; i < 240; i++)
    {
        double t = t + i*dt;

        switch(t)
        case t1 < t <= t2:
            break;
        case t2 < t <= t3:
            break;
        case t3 < t <= t4:
            break;
        case t4 < t <= t5:
            break;

    }


the other values are also double..
Last edited on
Swtich cases don't work that way. You're better of using if statements if it's gonna be of type double/float.
even for multiple cases??
Whhat do you mean multiple cases?

Edit: Yeah why not? Just do a few if/if else statements.
Last edited on
Like TarikNeaj says, switch case is not for ranges of numbers, it's for equivalence, if/ else is the way to go.

On a side note double t = t + i*dt; is going to give you some headaches here, what's the initial value of t?
ahhh! thanks moose! t should have been t1 :)..
Topic archived. No new replies allowed.