Hello everyone! This is my code, and I need a second opinion. My program executes and outputs correctly, but I don't have the matching output as my book. Can someone help me out and verify that this C++ program us coded correctly?
Here is the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
using namespace std;
int main()
{
long bound;
cout << "Enter a positive integer: ";
cin >> bound;
cout << "Fibonacci numbers < " << bound << ":\n0, 1";
long f0=0, f1=1;
while (true)
{
long f2 = f0 + f1;
if (f2 > bound) break;
cout << ", " << f2;
f0 =f1;
f1 = f2;
system("pause");
return 0;
}
}
|
Sample Output
Enter a positive integer: 1000
Fibonacci numbers < 1000:
0, 1, 1Press any key to continue . . .
Book show sample output to be this:
Enter a positive integer: 1000
Fibonacci numbers < 1000:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987
Press any key to continue . . .
Why is my output different than the book? Is the book's output a typo?