You are going through the array once only. Let's watch what happens:
Array at start: 12 9 14 3
i = 0
Compare a[0] and a[1], swap them round.
Array is now: 9 12 14 3
i = 1
Compare a[1] and a[2], they're in the right order, no swap.
Array is now: 9 12 14 3
i = 2
Compare a[2] and a[3], swap them round.
Array is now: 9 12 3 14
i = 3
Compare a[3] and a[4], except a[4] doesn't exist so you're comparing with some random value off the end of your array. This is a very bad idea. Don't do this.
Array is now: 9 12 3 14
So that's what your code does. Your sort algorithm simply doesn't work. You've tried to implement a bubble sort, but you've missed part of it. You need to keep doing this, over and over (except DON'T try to use a[4]) until no swaps happen. You need to keep repeating the for loop until no changes happen.
I tried i < 4 - 1 (line 8) but that doesn't work either. Kind of stuck as to what to write. Your explanation is very clear, though. Thanks a lot for that.
I understand what you said initially. I just want to know what I need to change in my for loop in order for this thing to work once and for all because I know I have the right idea I'm just missing something really minuscule .