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

Revised to put the input, "work" and output 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);
float getROI(const float endValue, const float beginValue, const int days);
void DisplayResults(const float result);

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 = (int)PromptAndGet("Please enter the maturation period in days: ");

    APR = getROI(denomination, purchasePrice, maturityDays);

    DisplayResults(APR);

    return 0;
    }

float PromptAndGet(const string& prompt)
    {
    float 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);
    }

void DisplayResults(const float result)
    {
    //display results in a specific format
    cout.precision(2);
    cout.setf(ios::fixed);
    cout << endl << "The APR of your T-bill is: " << result << "%" << endl;
    }