Sir, First of all logic is a logic, no matter where you implement it.
It doesnt matter if it is C or C++ or any other language. You can implement it anywhere you want. And Secondly yes you can do that , and the logic you have used will work perfectly fine. And what is your question all about?? Regards, Sunil.H.V.
