fibonacci problem

This is a discussion on fibonacci problem within the C++ Programming forums, part of the General Programming Boards category; Ok so I coded the following: Code: #include <iostream> using namespace std; int main() { int days, endday, pounds; cout ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    4

    fibonacci problem

    Ok so I coded the following:

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    int days, endday, pounds;
    cout << "Please enter in the amount of pounds: ";
    cin >> pounds;
    
    cout << "Please enter in the days: ";
    cin >> days;
    
    cout << "Please enter the last day you want to do this calcuation: ";
    cin >> endday;
    
    int numbers=pounds;
    
    for(int i=days;i<=endday;i=i+days)
    {
    if (days==i)
    pounds=pounds;
    else
    {
    pounds=pounds+(numbers/2);
    numbers=pounds;
    }
    
    
    cout << "The day is " << i << " and the pounds are " << pounds << endl;
    }
    }


    But I dont get the right values for "pounds"

    For instance I get :


    Please enter in the amount of pounds: 10
    Please enter in the days: 5
    Please enter the last day you want to do this calcuation: 25
    The day is 5 and the pounds are 10
    The day is 10 and the pounds are 15
    The day is 15 and the pounds are 22
    The day is 20 and the pounds are 33
    The day is 25 and the pounds are 49
    Press any key to continue


    what I need is day 10 to be 20, day 15, 30, day 20 to be 50 etc

    Thanks for any help!

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Sorry, but this is just wrong...

    Code:
    pounds=pounds;
    Obvious statement?

    Basically, there is absolutely no need to put that in the loop. Initialize pounds before the loop or inside the loop next to i, but do not initialize it to itself. That's rather rediculous.
    Last edited by MacGyver; 03-24-2007 at 06:12 PM.

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    The Fibonnaci sequence requires the first two variables of the sequence to be defined, and is thereafter defined as a(n) = a(n-1) + a(n-2). This is just funky.

    Code:
    pounds=pounds+(numbers/2);
    numbers=pounds;

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 04:46 PM

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