String Troubles

We are posed with this problem.

An office furniture company sells furniture in three colors: red, black and green. Every item in their inventory system has a 5-character code.
a. The first three characters are always used to represent the furniture type. If the first three characters are T47 then the furniture is a table, if the first three characters are C47 then the item is a chair
b. The last two characters are always used to represent color. If an item is red, the last two characters are
I have started over completely from this. But any guidance on this would be much appreciated.
On a string of length 5, substr(4,2) is only the last character. Indexing begins at 0, not 1.

To get a string that consists of the last two characters of any string (assuming a length of 2 or greater):

s.substr(s.length()-2);
Last edited on
Topic archived. No new replies allowed.