/********************************************************************************************
3_29r2.cpp
    Jim Millard
    for CO311

Revised to put the input and "work" in separate functions

Simple program that calculates the APR on a T-bill based on standard purchase criteria

********************************************************************************************/
#include <iostream>
#include <string>
using namespace std;

float PromptAndGet(const string& prompt);
int PromptAndGet(const string& prompt);

float getROI(const float endValue, const float beginValue, const int days);

int main()
    {
    int maturityDays;
    float denomination, purchasePrice, APR;

    //inform and prompt the user
    cout << endl << "This program will compute the APR (annual percentage rate) on" << endl;
    cout << "a Treasury bill." << endl;
    denomination = PromptAndGet("Please enter the matured value of the T-bill: $");
    purchasePrice = PromptAndGet("Please enter the price you paid for the T-bill: $");
    maturityDays = PromptAndGet("Please enter the maturation period in days: ");

    APR = getROI(denomination, purchasePrice, maturityDays);

    //output the results
    cout.precision(2);
    cout.setf(ios::fixed);
    cout << endl << "The APR of your T-bill is: " << APR << "%" << endl;

    return 0;
    }

float PromptAndGet(const string& prompt)
    {
    float temp;
    cout << prompt;
    cin >> temp;
    return temp;
    }

int PromptAndGet(const string& prompt)
    {
    int temp;
    cout << prompt;
    cin >> temp;
    return temp;
    }

float getROI(const float endValue, const float beginValue, const int days)
    {
    const int yearDays = 365;

    //interim storage objects
    float interestFactor, periods;

    periods = yearDays/Days;
    interestFactor = endValue/beginValue - 1.0;
    return (100.0 * interestFactor * periods);
    }