From Milnor and Stasheff:
If the $n$-dimensional manifold $M$ can be immersed in $\mathbb{R}^{n+1}$ show that each Stiefel-Whitney class $w_i(M)$ is equal to the $i$-fold cup product $w_1(M)^i$.
From the Whitney duality theorem we immediately have that the dual Stiefel-Whitney classes $\bar{w_i}(M)$ are zero for $i>1$. But I don't see how to use this to show that each class is a cup product of the first Stiefel-Whitney class.
Looking at the second half of the question which is to show that $\mathbb{R}P^n$ can be immersed in $\mathbb{R}^{n+1}$ only if $n=2^r-1$ or $2^r-2$ is not hard - the dual total Stiefel-Whitney classes can only be 1 or $1+a$. In the first case we get that the total Stiefel-Whitney classes must also be 1, which is true when $n=2^r-1$, and in the second we find $w(M)=1+a+a^2+ \cdots + a^n$, which is true if $n=2^r-2$ (I think that all works).
Is there any way to salvage an argument for the first part of the question from this? Indeed for a codimension 1 immersion the dual total Stiefel-Whitney class can only be 1 or $1+\bar{w_1}(M)$. But I can't see how this implies that $w_i(M) = w_1(M)^i$.
Any hints/tips?
Edit I think I actually had it written above! I really only need to worry about the case where $\bar{w_1}(M) \ne 0$, else all the non-zero Stiefel-Whitney classes are zero. So I can construct the formal inverse of $1+\bar{w_1}(M)$ which is given by $ \begin{eqnarray*} w_1 &=& \bar{w_1} \\ w_2 &=& \bar{w_1}^2+\bar{w_2} = w_1^2 \\ w_3 &=& \bar{w_1}^3+\bar{w_3}=w_1^3 \end{eqnarray*} $ and in general $w_i(M) = w_1(M)^i$