It's not in accordance with the forum requirement to use code blocks.
Also please use indenting; you may not see the point of it yet but it makes code a lot easier to read.
As for whether it is in accordance with the project requirements, well, you tell us. Does it work?
If not what does it do wrong? Give input and output, stating what the output should be.