This entire code needs proper formatting - spaces on both sides of math operators and after all commas.
Also, do you need to allocate the arrays dynamically, won't a static stack-based array be enough? Get rid of all the `new` and `delete`.