added cout coins algorithm