User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,969 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,760 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 525 | Replies: 3 | Solved
Reply
Join Date: Nov 2007
Posts: 8
Reputation: kidjl is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kidjl kidjl is offline Offline
Newbie Poster

Help [urgent] Need Help on my Visual C++

  #1  
Nov 26th, 2007
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;
	   
	}
	

}
Last edited by Ancient Dragon : Nov 26th, 2007 at 9:35 am. Reason: corrected code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: Dundee, Scotland
Posts: 12,855
Reputation: jbennet is just really nice jbennet is just really nice jbennet is just really nice jbennet is just really nice 
Rep Power: 32
Solved Threads: 304
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: [urgent] Need Help on my Visual C++

  #2  
Nov 26th, 2007
do a google for SYSTEM("Pause")
TRY MY SUGGESTIONS AT YOUR OWN RISK

Master of puppets Im pulling your strings, blinded by me, you cant see a thing. Master! Master!
Reply With Quote  
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,817
Reputation: niek_e is a name known to all niek_e is a name known to all niek_e is a name known to all niek_e is a name known to all niek_e is a name known to all niek_e is a name known to all 
Rep Power: 11
Solved Threads: 189
niek_e's Avatar
niek_e niek_e is offline Offline
Posting Virtuoso

Re: [urgent] Need Help on my Visual C++

  #3  
Nov 26th, 2007
Add:
  1. cin.ignore();
  2. cin.get();
  3. 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.

regards Niek

[edit]
Originally Posted by jbennet View Post
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

Niek
Last edited by niek_e : Nov 26th, 2007 at 8:18 am.
Want better/more replies to your questions? Wrap your code in [code] [/code] tags!
do NOT pm me for help, in the best case, you'll get ignored
Reply With Quote  
Join Date: Apr 2005
Location: Dundee, Scotland
Posts: 12,855
Reputation: jbennet is just really nice jbennet is just really nice jbennet is just really nice jbennet is just really nice 
Rep Power: 32
Solved Threads: 304
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: [urgent] Need Help on my Visual C++

  #4  
Nov 26th, 2007
i think hes using VC6 actually
TRY MY SUGGESTIONS AT YOUR OWN RISK

Master of puppets Im pulling your strings, blinded by me, you cant see a thing. Master! Master!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 9:12 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC