// fibonacci.cpp -- This program computes a student's grade
// CSCI 111-03
// Source -- Open Source

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdlib>
#include <fstream>
using namespace std;

// Prototype
long fibonacci(int);

int main() {

	// initiate variable
	int n;

	cout << "Dylan Brucki -- Lab 7" << endl << endl;

	// prompt user input and output fibonacci(n)
	cout << "Please enter a number 'n'" << endl;
	cin >> n;
	cout << "The nth term in the Fibonacci sequence is " << fibonacci(n) << endl;


	// pause command window and then return 0
	system("pause");
	return 0;
}

long fibonacci(int n){

	// start sequence with first two terms
	if (n == 0)
		n = 0;
	else if (n == 1)
		n = 1;
	else if (n == 2)
		n = 1;
	// recursion for the sequence to call on the function, then assign to n
	else if (n > 2)
		n = fibonacci(n - 1) + fibonacci(n - 2);
	// error for negative number
	else{
		cout << "Please try again and enter a positive number" << endl;
		system("pause");
		return 0;
	}

	// return nth term
	return n;

}
