You are working from the inside out in your formula, which looks to be like the best way to approach it. You aren't getting your formula coded right though.
Your formula for level n is 1 + (1/n)( value for level n + 1 ).
Now look at what you actually coded on the line in bold.
nfavenom wrote:
void main ()
{
double n;
cout << "please input number:";
cin >> n;
double m = 1.0 + 1.0 / n;
int i=n-1;
while (i>0){
m = 1.0 + 1.0/(m*i);
--i;
}
cout<<"number is "<<m<<endl;
}
There are also a few other problems with this code as well, so once you fix the line in bold, you aren't done.
In particular:
1) You have the signature for main() wrong - check C++ documentation for what valid signatures for main() are,
2) n is of the wrong type and should be merged with one of your other variables,
and
3) not all values that the user might enter are appropriate. What values are not appropriate? What currently happens if the user enters such a value? How about doing something to deal with this.