Devi correggere anche questo

if(n==0)

Occhio a tutte le if ...