Is my logic correct

here is the link of my code : https://ide.codingblocks.com/s/375315

logic is correct but
there are few mistakes in implementation
i have commented the mistakes and write the correct one

Modified code