Why is the correct answer a^2-a+1 to this problem:

a^3+1/a+1

Because a^3 + 1 factors to

(a+1)(a^2 - a + 1)

so

(a^3+1)/(a+1) , notice the necessary use of brackets
= (a+1)(a^2 - a + 1) / (a+1)
= a^2 - a + 1, on the condition that a≠ -1