Youth afflicted with committing a sin

I am a youth, and have been afflicted with [committing] a sin, and every time I repent [to Allaah] from it, I go back to doing it; I [just] want to be free of it, [so] if I were to do it again, is it permissible for me to undertake an oath that I shall fast a day for the Sake of Allaah, or give in charity so [as a result of which] He will safeguard me from doing it again?