Need help with coding!!!

This is a discussion on Need help with coding!!! within the C++ Programming forums, part of the General Programming Boards category; i need help with this code. when i enter a number i want to see the sequence always give 2 ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    16

    Need help with coding!!!

    i need help with this code.

    when i enter a number i want to see the sequence always give 2 extra number. the two extra numbers are 0 and 1 but i need it to be included

    so if i wanted to see 10 numbers
    it would show: 0 1 1 2 3 5 8 13 21 34 55 89
    but i need it to show:
    0 1 1 2 3 5 8 13 21 34


    #include <iostream>
    using namespace std;

    int main (int argc, char* argv[])
    {
    int fib1 = 0;
    int fib2 = 1;
    int fib3;
    int numbers;


    cout<<"How many numbers would you like to see?";
    cin >> numbers;
    if (numbers < 2)
    cout <<"The number has to be bigger than ";
    if (numbers >= 2);
    cout<<fib1<<endl<<fib2<<endl;


    int count;
    for (count = 1; count <= numbers; count = count + 1)

    {

    fib3 = fib1 + fib2;
    cout << fib3 <<endl;
    fib1 = fib2;
    fib2 = fib3;

    }
    system("pause");
    return 0;
    }

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,698
    Count correctly.

    for (numbers -= 2; numbers > 0; --numbers)

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    Never mind the coding, how's the eyesight?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 01-25-2011, 02:03 AM
  2. Replies: 9
    Last Post: 03-20-2009, 05:22 PM
  3. Before Coding
    By cyberCLoWn in forum C++ Programming
    Replies: 16
    Last Post: 12-15-2003, 01:26 AM
  4. Coding Contest....
    By Koshare in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-14-2001, 04:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21