Thread: Simple program not working, don't know why

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by esbo
    It seems the problem is the line for the sum is never executed otherwise it would be atleast 1
    on the first pass?
    Yes, the statement to add to sum is never executed, but sum cannot be 1 since it must be an even number. The main problem is that Bakster is not generating the Fibonacci sequence, but rather a variant of it where the current number is twice of the previous plus the number just before the previous. Luckily, there is a simple fix involving the removal of a single character in the source code.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    22
    Quote Originally Posted by laserlight View Post
    Yes, the statement to add to sum is never executed, but sum cannot be 1 since it must be an even number. The main problem is that Bakster is not generating the Fibonacci sequence, but rather a variant of it where the current number is twice of the previous plus the number just before the previous. Luckily, there is a simple fix involving the removal of a single character in the source code.
    Ah yes, I see the problem now. Removing the '+' from '+=' on line 10 fixed it. Thanks a lot!

  3. #3
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Bakster View Post
    Ah yes, I see the problem now. Removing the '+' from '+=' on line 10 fixed it. Thanks a lot!
    Ha ha well spotted, it's always hard to find bugs in programs because they always do *exactly* what you tell them to do!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  2. Replies: 10
    Last Post: 09-07-2008, 11:38 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. simple frontend program problem
    By gandalf_bar in forum Linux Programming
    Replies: 16
    Last Post: 04-22-2004, 06:33 AM
  5. unable to get simple program working
    By toom in forum Linux Programming
    Replies: 1
    Last Post: 10-11-2003, 05:05 AM