You can make your main function quite a bit shorter. You have an exact copy of the code inside the loop outside the loop, which you can remove if you make sure the loop always runs at least once.
But before that, make the improvements std10093 suggested in post 9. Your shift function is implictly returning an int because you haven't specified a return type. You don't return anything though, and dangeous nonsense will ensure if you accidentally call shift in a context where the returned value is used.