Thread: Im new at this and i need help with assignment

  1. #1
    Registered User
    Join Date
    Dec 2001

    Exclamation Im new at this and i need help with assignment

    this year i joined computer science and am stuck on an assignment and i cant seem to finish it out of 3 question ive done 1 and 3 but number 2 im stuck on here is the q i would realy like some help my icq is 78828712 and email is please help asap

    2.. A Fibonacci sequence of numbers is computed by adding the first 2 numbers to get the third, the fourth is computed by adding the second and third and so on...

    1 1 2 3 5 8 13 21 34 .... n

    Write a C++ program which will prompt for the first 2 numbers of a sequence and then compute and print the first 20 numbers of Fibonacci sequence, 5 numbers to a line.

    Note that these numbers get big fast so you will want to provide enough space for them to print properly. The output should look similar to;

    1 1 2 3 5
    8 13 21 34 55
    89 144 ...

    The output must be sent to the screen as well as to a disk file, but input prompts should not be output to file.

    The program should continue to compute and print Fibonacci sequences until a 0 0 is entered. No negative numbers should be entered, and the numbers should be in ascending order, that is n1 <= n2 (you must test for these conditions and provide an error trap) The error message should be printed to both console window and output file.

    Test your program with a variety of inputs. When you are satisfied that it works properly use the following pairs as data for your final run.

    0 1
    1 1
    -1 1
    1 2
    1 3

    Hand in your source code, the text window, and the formatted output file.

  2. #2
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    you got to just do it man... this problem isn't terribly hard... but it is a bit long.

    Some tips...

    while (user_number_integer < 0)
    cout << "What is number 1: ";
    cin >> user_number_integer;

    //See how that keeps a person in until they enter a 0 or a positive number

    // Later on...

    you need to have an array with the first two positions that have numbers in them (the two that were given)

    add those two

    current = 3;
    first = 1;
    second = 2;

    integer_array[current] = integer_array[first] + integer_array[second];


    now loop back up above integer_array[current]... until current == 20

    after you fill your array... print each number to the screen and to file

Popular pages Recent additions subscribe to a feed