#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <string>
#include <limits.h>
using namespace std;

void changeGreeting(string* greeting_ptr){
  string greeting = "";
  cout << "Type your new greeting: ";
  getline(cin, greeting);
  *greeting_ptr = greeting;
  return;
}

void prequelize(string* quotes, int target,int dest){
  string prequels[4] = {
    "\"Hello there!\"",
    "\"It's over, Anakin. I have the high ground.\"",
    "\"I'm too weak. Unlimited power!\"",
    "\"Wipe them out. All of them.\""
  };
  *(quotes+dest) = prequels[target];
  return;
}

int main() {
  string greeting = "Hello World";
  string* greeting_ptr = &greeting;
  string quotes[10] = {
    "\"May the Force be with you.\"",
    "\"I have a bad feeling about this.\"",
    "\"Traveling through hyperspace ain't like dusting crops, boy!\"",
    "\"I love you.\" \"I know.\"",
    "\"Do. Or do not. There is no try.\"",
    "\"It's a trap!\"",
    "\"I find your lack of faith disturbing.\"",
    "\"These aren't the droids you’re looking for.\"",
    "\"Help me, Obi-Wan Kenobi. You're my only hope.\"",
    "\"Never tell me the odds!\""
  };
  string* quote_ptr = &quotes[0];

  int target,dest;
  char resp;
  bool valid;
  
  cout << *greeting_ptr << endl;
  changeGreeting(greeting_ptr);
  cout << *greeting_ptr << endl;

  cout << "\nOriginal Trilogy Quotes:\n";
  for(int i=0; i<(sizeof(quotes)/sizeof(string));i++){
    cout << i+1 << ". " << quotes[i] << endl;
  }

  srand(time(0));
  
  do{
    target = rand() % 4;
    dest = rand() % 10;
    prequelize(quote_ptr,target,dest);
    cout << "\nYour prequelized quotes:\n";
    for(int i=0; i<(sizeof(quotes)/sizeof(string));i++){
      cout << i+1 << ". " << quotes[i] << endl;
    }
    do{
      valid = false;
      cout << "Prequelize the list again? (y/n): ";
      cin >> resp;
      if(resp == 'y' or resp == 'n'){
        valid = true;
      }else{
        cout << "ERROR. Please input a 'y' or 'n'.\n";
      }
    }while(valid == false);
  }while(resp == 'y');

  return 0;
}