converting if/else if statement into switch
i need help with this..Explain why you cannot convert the following if/else if statement into a switch statement
1 2 3 4 5 6
|
if (temp == 100)
x = 0;
else if (population > 1000)
x = 1;
else if (rate < .1)
x = -1;
|
switch(temp)
checks value of temp case by case, and executes action relevant if case value of temp is matched.
1 2 3 4 5 6
|
if (temp == 100)
x = 0;
else if (population > 1000)
x = 1;
else if (rate < .1)
x = -1;
|
here ur actions are not based on varying values of a single variable temp, so u cannot use a switch case.
thank you sir for your help.
Topic archived. No new replies allowed.