/* G. Hagopian
11. Write a program that writes out the first so many values of the Fibonacci series,
that is, the series that starts with 1 1 2 3 5 8 13 21 34. The next number of the series
is the sum of the two previous ones. Find the largest Fibonacci number that fits in an int.
*/
#include
using namespace std;
int fibonacci(int, int);
int main()
try {
int last = 1, next2last = 1;
cout << next2last << ", " << last << ", ";
while (last > 0) {
int temp = last;
last = fibonacci(next2last, last);
next2last = temp;
cout << last << ", ";
}
}
catch (exception& e) {
cerr << e.what();
}
int fibonacci(int x, int y) {
if (x + y < 0) throw(runtime_error("too tall to live"));
return x + y;
}