Maybe this should be in the beginner forum but I'm trying to make a fibonacci sequence with some user inputs. I'm using arrays for this, the user inputs are for the Nth term and the starting number (as in the number in front of 0).
My problem is that when the program runs it's an infinite loop which constantly prints the starting number. Which, I think, means that my WHILE loop isn't coming to an end and my 'count' variable isn't increasing. Sorry to bother you guys, does anyone know what I've done wrong?
On line 15, it is not allowed by the C++ standard to declare an array from a non-const number like this. SOme compilers support it, but you should get out of this habit and use an STL container or dynamic memory (whichever is allowed, preferably STL containers).
Between line 18 where you declare comp and line 23 where you use it, you never initialize comp. Can't you just do a for loop or make the while condition while count < term?
On line 25, you increment count, but on line 26 you decrement it again. Maybe you mean count-1 and not count--?
15: int seq[term];
vla are illegal in c++, you may use std::vector
18: bool comp;
You did not initialize the variable, you intent to use it later (uninitialized) in line 23
23: while (comp == false)
`comp' is a bool, you could simply while( comp )
26: seq[count] = seq[count--] + seq[count-2];
undefined behaviour.
You modify count in that line ¿Should `seq[count]' use the old or new value? (ditto for `seq[count-2]')
28: if (count == term)
You have incremented `count' (line 25), then decremented it (line 26). You did nothing
Also, you may use that as your loop condition
This is typically a problem on Windows, caused by really dumb IDEs that don't know enough to keep the console open after the program finishes. However, it does strike right at one of the main philosophical problems with the way you are thinking about programming. After all, a console program should be run from the console --else once it terminates, the console should disappear