// Chapter 08, exercise 02: function that prints a vector<int> to cout
// Exercise 03: create a vector of Fibonacci numbers, print them with function
// from exercise 02
// Exercise 04: find approximation to maximum int value

#include <iostream>
#include <vector>
using namespace std;

void print(const string& label, const vector<int>& v) {
	cout << label << " (" << v.size() << "): {";
	for (int i = 0; i < v.size(); ++i) {
		if (i % 8 == 0) cout << endl;
		cout << v[i];
		if (i < v.size() - 1) cout << ", ";
	}
	cout << "\n}\n";
}

// fill a vector with the Fibonacci sequence
void fibonacci(int x, int y, vector<int>& v, int n) {
	if (n < 1) runtime_error("There must be at least one number in the sequence.");
	v.push_back(x);
	if (n == 1) return;
	v.push_back(y);
	if (n == 2) return;
	for (int i = 2; i < n; ++i)
		v.push_back(v[i - 2] + v[i - 1]);
}

int main() {
	int x = 0;
	int y = 0;
	vector<int> v;
	int n = 0;

	cout << "Enter first number in the generalized Fibonacci sequence: ";
	cin >> x;
	cout << "Enter second number in generalized Fibonacci sequence: ";
	cin >> y;
	cout << "Enter number of elements in sequence: ";
	cin >> n;

	fibonacci(x, y, v, n);

	string s = "This Fibonacci sequence is ";
	print(s, v);
}
