Explore BrainMass

ranges and functions

You have functions that you wish to call for various individual year values, as well as ranges of years, and you are deciding on whether to use an if statement or a switch statement. The ranges and functions are:

o 1900 to 1969 - functionA()

o 1969 to 2000 - functionB()

o 2001 - functionC()

o 2002, 2003 - functionD()

o 2004 and beyond - functionE()

Do you think it would be better to set this up as an if statement, a switch statement, or a combination? Write the code if it helps to explain your answer.

Solution Preview

Since for many year values you need to execute functionA() and functionB(), it would be recommended to setup the code using if statements otherwise one has to write too many case statements for each year in the range to execute the corresponding function. The following piece of code would ...

Solution Summary

This job applies ranges and functions.