Thread: Need help with coding!!!

  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
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Count correctly.

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

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 01-25-2011, 03: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, 02: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