aboutsummaryrefslogtreecommitdiff
path: root/entries/braxtonh/homework/fib.cpp
blob: 900c9d0e5187588330510c44e4f62af782ec1479 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "fib.hpp"

#include <string>
#include <iostream>
#include <stdexcept>

using namespace std;

int Fibonacci::fib(const int n) const
{
	// cout << "start" << endl;
	if (n < 0) {
		// HOW??
		cout << "wtfff got ( " << n << " )" << endl;
		// https://stackoverflow.com/questions/8480640/how-to-throw-a-c-exception
		throw invalid_argument("received negative value");
	} else if (n == 0) {
		// cout << "********************* LINE 12" << endl;
		// https://stackoverflow.com/questions/1451170/in-the-fibonacci-sequence-is-fib0-0-or-1
		return 0; //1; ??????
	} else if (n == 1) {
		// cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!! LINE 15" << endl;
		return 1;
	} else {
		// cout << "GOT TO LINE 19" << endl;
		// cout << "got here" << endl;
		// int retVal = fib(n - 1) + fib(n - 2);
		return fib(n - 1) + fib(n - 2);
		// // cout << "here" << endl;
		// cout << "returning: (" << retVal << " )" << endl;
	}
}