Lab 2

Purpose

This week's lab is intended to get you a little more practice with basic C++. Please look over the code I have given and read the comments. This code is intended to be a guide as you start writing your own C++ code and could be used to get you started with later projects.

Problem

We're going to be looking at using an Exponential growth. There are many places in science, engineering and business where exponential growth occurs. For simplicity, we'll use Compound Interest.

Formula for calculating compound interest:

A = P\left(1 + \frac{r}{n}\right)^{nt}

Where,

Additionally, we'll look at interest compounded continuously. That uses a similar formula but removes the number of times per year it is compounded

A=Pe^(rt)

In order to raise something to a power, we'll need to use the pow function from the cmath library. Additionally, you'll need to make use of the math constant M_E, which will give you e, the base for the natural log

#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
using std::cin;
using std::cout;
using std::endl;
using std::pow;
int main()
{
    double answer;
    int principle;
    double rate;
    int number;
    int time;
    cout <<  "Please tell me how much money you started with: ";
    cin >>  principle;
    cout <<  endl;
    cout << "Please tell me the rate for the investment: ";
    cin >> rate;
    cout << endl;
    cout << "Please tell me how many times a year your interest is compounded: ";
    cin >>  number;
    cout << endl;
    cout << "Please tell me how many years you want to invest your money: ";
    cin >> time;
    //calculation goes here

    cout << "After " << time << " years you're initial investment of " << principle << " compounded every "  
    << number << " times per year at " << rate << " interest rate will be worth " << answer << endl << endl;

//now let's compute using the same values, but instead we'll use compounded continuously.

    cout << "After " << time << " years you're initial investment of " << principle << " compounded continuously at "  
    << rate << " interest rate will be worth " << answer << endl << endl;
    return 0;
}

Procedure

Just like last week, you may work with a partner if you choose.

You can start with the program I gave up above. It has all the necessary input and output. You will need to read through it to understand the parts that I wrote and how to put them together.

Additionally, you'll need to investigate the pow function. It has the basic format of pow( base, power ) and it will return a value. Something like this would give you x^2. y = pow( x, 2 );

Feel free to make up and variables you may need for any intermediate calculations. If you do, don't forget to declare them first, e.g. int myNewVariable.

Grading

For grading, you need to turn in your CPP file to Scholar by Friday at noon. Make sure you don't submit your obj or your exe.