•
•
•
•
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
![]() |
| |
•
•
Join Date: Nov 2007
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
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
(!) 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
•
•
Join Date: Apr 2005
Location: Dundee, Scotland
Posts: 12,855
Reputation:
Rep Power: 32
Solved Threads: 304
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,817
Reputation:
Rep Power: 11
Solved Threads: 189
Add:
to your code just before the last closing bracket to keep the terminal-window open until you press a key.
change:
change
regards Niek
[edit]
First of all: it's
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
cplusplus Syntax (Toggle Plain Text)
cin.ignore(); cin.get(); return 0;
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]
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
do NOT pm me for help, in the best case, you'll get ignored
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Urgent solution needed (C++)
- Visual C++ and Lex/Yacc (Software Developers' Lounge)
- My Pc Has Urgent Problems.. (Troubleshooting Dead Machines)
- I Need Urgent Reply (MS SQL)
- TechNet TV - Visual Studio 2003 ....... (VB.NET)
- Problem in Serial Communication In Visual Basic (Visual Basic 4 / 5 / 6)
- cannot to create project in Windows Server 2003 with Visual Studio.NET 2003 (ASP.NET)
- Importing SQL Script File - Urgent !! (Database Design)
- Visual C++ and Excel (C++)
- Visual Basic.net (VB.NET)
Other Threads in the C++ Forum
- Previous Thread: winres.h problem
- Next Thread: How to Copy AnsiStrings



Hybrid Mode