If you look at what the error says, you'll see that you're missing an "end if"
If you look at it again, you'll see you're also missing an "End loop"
if average > 50 then
else if average > 50 then
put "You are in the middle"
Both of those conditions are > 50. The second one should be <50.