In this case use switch or if?

1

I have an exercise to do that consists of the following:

The user informs the salary, and depending on the value informed, it gains an increase according to the table. Example: From 1000 to 1500 he gains 10% From 1500 to 2000 he earns 5% 2000 he does not gain any increase.

I thought of doing using multiple ifs , but in case, would it be better to use switch ? Why?

    
asked by anonymous 17.03.2017 / 05:15

1 answer

3

The question does not make the criteria very clear, but each percentage is likely to be applied according to a range of values. If so, only if works. switch does not allow to work with tracks, only with constants.

But if for some reason it is possible to reduce to a constant from a formula using the mean wage, then not only could it use switch , but perhaps it would even be the case to use an array and do not use a switch .

    
17.03.2017 / 09:40