Thread: Fibonacci sequence in c++

  1. #31
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Oh you are outputting count in your loop remove that and see if it looks better.

  2. #32
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    @whiteflag
    Yes, it works, but it is not proper. If your self taught you can make things ambigious. Lets give you an example. This compiles so it must be ok to use wherever I want to use it then.

    Code:
    int mymax (int(*a)(int(*)(int(*)()),int(*)(int(*)(int**))), int(*b)(int(*)
    (int(*)()),int*,int(*)(int(*)()))){return (int)((((int(*)(int(*)(int(*)()),int(
    *)(int(*)())))a)> ((int(*)(int(*)(int(*)()),int(*)(int(*)())))b))?((int(*)(
    int(*)(int(*)()),int(*)(int(*)())))a):((int(*)(int(*)(int(*)()),int(*)(int(*)(
    ))))b));??>

  3. #33
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Yes, it works, but it is not proper. If your self taught you can make things ambigious. Lets give you an example. This compiles so it must be ok to use wherever I want to use it then.
    You said "wherever I want to use it," well: "Proper" is bull......... What if I wanted to use it for an obfuscated code contest? Is it not proper there, as well as far as the standard is concerned? This has nothing to do with how anyone is taught.

  4. #34
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Standard code reads a certain way. Even if code compiles and works it can still be unneeded and a waste making it harder to read it is better to write what you need to write nothing more nothing less. More characters give more places to make mistakes. This guy is just starting it would be better to at least give him normal standard stuff instead of hey it compiles and works, but it isn't how he is being taught I would bet, which teaching him wrong here will only make it harder to learn C++.

  5. #35
    Registered User
    Join Date
    Feb 2011
    Posts
    16
    i need help its not coming out right

  6. #36
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    What is your output?

  7. #37
    Registered User
    Join Date
    Feb 2011
    Posts
    16
    idk i need to start over again. a fresh start. can you help me through?

  8. #38
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    You are very very close with what you have.

  9. #39
    Registered User
    Join Date
    Feb 2011
    Posts
    16
    but the fibonacci sequence is not even coming out right and i still need the if statement

  10. #40
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Standard code reads a certain way.
    I will repeat it: return(0); is a standards compliant statement. Do you really want to argue that?
    Even if code compiles and works it can still be unneeded and a waste making it harder to read it is better to write what you need to write nothing more nothing less.
    Really? Well like I said before, you need parens in many cases where you opt to remove whitespace between keywords and tokens.

    More characters give more places to make mistakes.
    Many students mourn the omission of a simple ; where one is necessary and the compiler responds with a digest hundreds of lines long.

    This guy is just starting it would be better to at least give him normal standard stuff instead of hey it compiles and works, but it isn't how he is being taught I would bet, which teaching him wrong here will only make it harder to learn C++.
    Again, what sparked this conversation was a statement from you that return(0); was wrong when it is clearly not and you merely insisting the contrary. And it is not at all strange to encounter it in code. Some people just do it because they actually find it clearer.

    Programming is not how many keys you press.

    And I consider it a greater crime to insist that blatant lies are facts.

  11. #41
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Code:
    #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;
        int count;
        cout<<fib1<<endl<<fib2<<endl;
        for (count = 1; count <= numbers; count = count+1)
        {
            /*cout << count << " ";*/
    
            fib3 = fib1 + fib2;
            cout << fib3 <<endl;
            fib1 = fib2;
            fib2 = fib3;
    
        }
        system("pause");
        return 0;
    }

  12. #42
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Quote Originally Posted by whiteflags View Post
    I will repeat it: return(0); is a standards compliant statement. Do you really want to argue that?

    Really? Well like I said before, you need parens in many cases where you opt to remove whitespace between keywords and tokens.


    Many students mourn the omission of a simple ; where one is necessary and the compiler responds with a digest hundreds of lines long.


    Again, what sparked this conversation was a statement from you that return(0); was wrong when it is clearly not and you merely insisting the contrary. And it is not at all strange to encounter it in code. Some people just do it because they actually find it clearer.

    Programming is not how many keys you press.

    And I consider it a greater crime to insist that blatant lies are facts.
    At this point I will just point out you aren't even helping anything your flaming because you have issues. I said the code works I agree to that point it is not what is taught in schools. Leave things alone the way they are being taught if his teacher writes return 0; which all of mine did from 8086 programming to C/C++ and back.

  13. #43
    Registered User
    Join Date
    Feb 2011
    Posts
    16
    @kyo
    woow i was close. but i cud of never thought of that. thanks for keep trying to motivate me

  14. #44
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    as I said earlier you needed to take the count output out it was countin up between every fib number which wouldn't be the correct deal.

  15. #45
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    At this point I will just point out you aren't even helping anything your flaming because you have issues. I said the code works I agree to that point it is not what is taught in schools. Leave things alone the way they are being taught if his teacher writes return 0; which all of mine did from 8086 programming to C/C++ and back.
    Then I will just point out that you seem content to do his homework for him, which is all you are doing now.

    And as far as what is being taught in school, how do you know? Is it not one of your own personal faults if you did not realize that being able to use parens for grouping (which is taught) means that a lot of perhaps weird syntax is valid? Parroting teachers is only the most basic way to learn and it actually lead you to an incorrect conclusion on something really stupid.

    your flaming because you have issues
    The truth hurts.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. n-th element of the fibonacci sequence
    By me001 in forum C Programming
    Replies: 22
    Last Post: 09-24-2008, 03:27 AM
  2. Fibonacci Sequence
    By Dogmasur in forum C Programming
    Replies: 15
    Last Post: 08-10-2008, 07:55 AM
  3. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 12:52 PM
  4. Fibonacci sequence output statement
    By chocha7 in forum C++ Programming
    Replies: 10
    Last Post: 11-18-2004, 11:04 PM
  5. Fibonacci sequence
    By girliegti in forum C++ Programming
    Replies: 8
    Last Post: 09-30-2003, 10:40 PM

Tags for this Thread