// InvestmentPlanner.cpp : main project file.

#include "stdafx.h"

using namespace System;

// function prototype
void DisplayWelcome();
void DisplayProjectedValue(double amount, int years, double rate);
double GetInvestmentAmount();
int GetInvestmentPeriod(int min = 10, int max = 25);
void DisplayProjectedValue(double amount, int years);

int numberOfYourFunctionsCalled = 0;

int main(array<System::String ^> ^args)
{
    DisplayWelcome();
	Console::WriteLine(L"\nIllustration...");
    DisplayProjectedValue(10000, 25, 6.0);
	Console::WriteLine(L"\nEnter details for your investment:");
	double sum = GetInvestmentAmount();
	int period = GetInvestmentPeriod(5, 25);
	Console::WriteLine(L"\nYour plan...");
    DisplayProjectedValue(sum, period);

	Console::Write(L"\nNumber of your functions called: ");
	Console::WriteLine(numberOfYourFunctionsCalled);

    return 0;
}

void DisplayWelcome()
{
	numberOfYourFunctionsCalled++;

    Console::WriteLine(L"------------------------------------------");
    Console::WriteLine(L"Welcome to your friendly Investment Planner");
    Console::WriteLine(L"------------------------------------------");
    return;
}

void DisplayProjectedValue(double amount, int years, double rate)
{
	numberOfYourFunctionsCalled++;

	double rateFraction = 1 + (rate/100);
    double finalAmount = amount * Math::Pow(rateFraction, years);
    finalAmount = Math::Round(finalAmount, 2);
	Console::Write(L"Investment amount: ");
    Console::WriteLine(amount);
    Console::Write(L"Growth rate [%]: ");
    Console::WriteLine(rate);
    Console::Write(L"Period [years]: ");
    Console::WriteLine(years);
    Console::Write(L"Projected final value of investment: ");
    Console::WriteLine(finalAmount);
    return;
}

double GetInvestmentAmount()
{
	numberOfYourFunctionsCalled++;

    Console::Write(L"How much money do you want to invest? ");

    String ^ input = Console::ReadLine();
	double amount = Convert::ToDouble(input);
    return amount;
}

int GetInvestmentPeriod(int min, int max)
{
	numberOfYourFunctionsCalled++;

    Console::Write(L"Over how many years [");
    Console::Write(L"min=");
    Console::Write(min);
    Console::Write(L", max=");
    Console::Write(max);
    Console::Write(L"] ? ");

    String ^ input = Console::ReadLine();
	int years = Convert::ToInt32(input);
    return years;
}

void DisplayProjectedValue(double amount, int years)
{
    numberOfYourFunctionsCalled++;

    Random ^ r = gcnew Random();
    int randomRate = r->Next(0, 20);
    DisplayProjectedValue(amount, years, randomRate);
}                                                      



