////////////////////////////////////////////////////////////////////////// // This program will be able to calculate Fibonacci numbers up to a // // User entered number of numbers in the sequence EG. // // User enters 5 1,1,2,3,5 would be the output // ////////////////////////////////////////////////////////////////////////// #include <cstdio> #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { unsigned int var1, var2, var3, var4, var5; var5=0; cout << "enter the number of places in the fibonacci sequence you wish to calculate:\n "; cin >> var1; cout << "there will be " << var1 << "places in the sequence calculated\n "; var2=0; var3=1; while (var1>0) { var4=var2+var3; cout << var2 << "\n"; --var1; var2=var3; var3=var4; ++var5; if (var4>=4000000000) { cout << var5 << "places were calculated\n"; goto end; } } end: system("PAUSE"); return EXIT_SUCCESS; }

Now with this it stops after 68 iterations of the loop. I realize that i put in a break command if the value is over 40000000000 but thats the margin of accuracy ive recieved. i would like it to be able to do thousands of iterations of the loop outputing the result accurately. so that if i asked it for 10,000 numbers in the sequence it will happily do it accurately. Any help would be appreciated. Im also just learning C++, which is why i chose to do a relatively simple code.

EDIT i just ran the code again and realized i should have put the failsafe for a unsigned int only but i put it for an unsigned long. please dont mind that.

This post has been edited by **dnelson1**: 11 December 2009 - 12:04 AM