Problem 8 solved.

Using switch case.