Fibonacci Sequence

I have written this code to calculate the nth number in a Fibonacci Sequence. However once I debug the code and enter a value, the box disappears. Does anyone have any idea why?

#include <iostream>
using namespace std;
int main()
{
int x, i, j, n, m;
cout <<"Enter the total number \n";
cin >>n;
cout <<"Total number of the series is \n"<< n;
i=0;
j=1;
cout <<"\n" << i << "\n" << j;
for(x=0;x<=n;x++)
{m=i+j;
cout <<"\n"<<m;
i=j;j=m;
}

cin.get();

return 0;
}
However once I debug the code and enter a value, the box disappears.


What?
type cin.ignore(); after cin.get();

or

type getch(); instead of cinget(); cin.ignore(); but don t forget to #include <conio.h>
Don't you already have this exact same thread here? http://cplusplus.com/forum/beginner/94550/
After this instruction cin >>n; there is a newline character remaining in the input buffer.

The cin.get(); statement will retrieve that newline, and the program continues. if you want the program to wait, add a second cin.get(); after that.

As you can see from previous suggestions, there are many ways to solve this, it's a very common problem, which is why there is a sticky thread titled "Console Closing Down" at the top of the page:
http://www.cplusplus.com/forum/beginner/1988/
Topic archived. No new replies allowed.