Hello everybody. I am beginner in programming.....However, recently i recieved a simple assigment from my Professor. The assigment asks me to use C++ and create a programe that will display a series of Fabonacci numbers after the user enter a number . For example if the user enter 10 , then on the screen it will display " 0 1 1 2 3 5 8 13 21 34 " . That the 3rd number equals 1st number plus 2nd number. Anyways, when i starts debugging , the window always disapears after i type in a number after the question "How many series of Fabonacci numbers do you want to see?" I know that my codes are not right...but i just can't go on if the window keeps disapearing on me...Would some one please help me...
(!) I have already fixed all the pop-up syntax errors

#include<iostream>
using namespace std;

void main()
{
	int Num1=0;
	int Num2=1;
	int Sum;
	int Usernum;
	int Count=1;

	cout << "How many Fibonacci series numbers do you want to see??"" ";
	cin >> Usernum; 

	
	while( Count < Usernum)
	{
	   cout << Num1 <<" ";
	   Sum = Num2 + Num1;
	   Num1 = Num2;
	   Num2 = Sum;
	   Count = Count + 1;
	   
	}
	

}

Add:

cin.ignore();
cin.get();
return 0;

to your code just before the last closing bracket to keep the terminal-window open until you press a key.
change: void main() to int main() Your (turbo?) C++ compiler might not complain about it, but most of the compilers will. void main() doesn't exist.

change while( Count < Usernum) to while( Count <= Usernum) or else your last number will not be displayed.


[edit]

do a google for SYSTEM("Pause")

First of all: it's system("pause"); (case sensitive)
Second: I'm not a fan of this solution because it's not portable. Output in linux would be: bash: pause: command not found

Edited 6 Years Ago by Nick Evan: n/a

This question has already been answered. Start a new discussion instead.