An office furniture company sells furniture in three colors: red, black and green. Every item in their inventory system has a 5-character code. The last two characters are always used to represent color. If an item is red, the last two characters are “41”. If an item is black, the last two characters are “25”. If an item is green, the last two characters are “30”. Ask the user to enter a 5-character code. Use the last 2 characters to determine the color. Display the color in the console window (“Red”, “Black” or “Green”). If the inventory code is not exactly 5 characters long, or if the last two characters are neither “41”, “25” nor “30”, display an error message (“Invalid inventory code”). [Hint: Use the substr function to extract the last two characters of the string and see whether the extracted substring is “41”, “25” or “30”).
This allows the user to enter a number, and checks it's length. You now need to check the last two numbers using the substr command. If the last two numbers don't equal what they should, display an error. If it does equal what it should, display the color. Make sense?