//recursion from class 3/25/16
//CSI 201 - Dr. Ramsey
#include <iostream>
using namespace std;

void printStars(int);
void printN(int);
int sumN(int);

int main() {
  cout << "Recursion Program!" << endl;
  cout << "Recursive functions call themselves!" << endl;
  cout << "Example: Output 'n' stars: first output a star, then output n-1 stars" << endl;

  int howManyStars;
  cout << "How many stars do you want to output: ";
  cin >> howManyStars;
  printStars(howManyStars);
  cout << endl;
  //print numbers n through 1
  //print n, then print n-1 through 1
  //base case: 0 - print nothing
  //base case: 1  -just print 1
  int howManyNumbers;
  cout << "How Many Numbers to Print:";
  cin >> howManyNumbers;
  printN(howManyNumbers);
  cout << endl;
  cout << sumN(howManyNumbers) << endl;
}

//a function to print a number
//of stars horizontally
//uses recursion
void printStars(int n) {
  if (n <= 0) { //base case/stopping case
    // do nothing if no stars should be printed
  }
  else { //n is 1 or more
    printStars(n-1);
    cout << "*";
  }
}


//print the numbers N through 1
//recursively -using 1 as the base case
void printN(int n) {
  if (n == 1) { //base case
    cout << 1;
  }
  if (n > 1) { //recursive case
    printN(n - 1);
    cout << " " << n;

  }
}

//sum up the numbers from 1 through N
//if 1, simply return 1
//if more than 1 return n + the sum from 1 to n-1
//if less than 1, just return 0
int sumN(int n) {
  if (n == 1) { //base case
    return 1;
  }
  if (n > 1) { //recursive case
    return n + sumN(n - 1);
  }
  return 0; //all other cases
}
