/* Program to compute the Fibonacci function both iteratively and
 * recursively.
 *
 * Input:  a positive integer x
 * Output: the xth element of the Fibonacci sequence
 *
 * Written by:   Larry R. Nyhoff
 * Written for:  Lab Manual for C++: An Introduction to Data Structures
 *
 * Add other documentation required by your instructor such as your name, 
 * course number, and the current date.
 *************************************************************************/

#include <iostream>
using namespace std;

/* An iterative (nonrecursive) Fibonacci function
 * 
 * Receives: integer x
 * Returns:  the x-th Fibonacci number
 -------------------------------------------------*/

int IterFibonacci(int x)
{
  int
    nextFib = 1,        // the next Fibonacci number to be calculated
    previousFib = 1,    // the Fibonacci number before it
    beforePreviousFib;  // the Fibonacci number before that one

  for (int i = 3; i <= x; i++)
    {
      // First, update the previous and before previous values
      beforePreviousFib = previousFib;
      previousFib = nextFib;

      // Then compute the next Fibonacci value
      nextFib = previousFib + beforePreviousFib;
    }

  return nextFib;
}

/* RecFibonacci is a recursive Fibonacci number calculator
 *
 * Receives: postive integer n
 * Returns:  the n-th Fibonacci number
 * Add other documentation required by your instructor
 ********************************************************/

int RecFibonacci(int x)
{
  // Add statements for RecFibonacci() here
}

int main()
{
  int x;
  do
  {
    cout << "Please enter a positive integer: ";
    cin >> x;
  } while (x <= 0);

  // Now print the result of the iterative version of the function
  cout << "Iterative fib(" << x << ") = " << IterFibonacci(x) << endl;

  // Now print the result of the recursive version of the function
  //cout << "Recursive fib(" << x << ") = " << RecFibonacci(x) << endl;
}


