Create interest program, and set a table.

Using a given interest rate, balance, and term output a table of adjusted balances each year for the number of years specified by the term. For this assignment you will use a simplified formula:

interest = balance * rate / 100.0;

Basically you want to add the interest to the balance each year.

This assignment must be done using a for loop to calculate the table.

You can output fixed width using the following:

setw(int n) -- sets the field width
fixed -- sets fixed length
setprecision(int n) -- sets decimal place

You must also include <iomanip> in order to set the precision.

Input: interst rate (like 5.0), balance, term
Process: Compute a running balance
Output: Table of adjusted balances


------ I'VE BUILT THE CODE SO FAR; BUT I'M HAVING A HARD TIME UNDERSTANDING IT, BY OUTPUTTING A TABLE.
--------------------------------------------------------------------------

#include<iostream>
#include<iomanip>
using namespace std;

int main ()
{
double money=0.0;
double interest=0.0;
int year=0;
int C=0;

cout<<"Enter an amount to invest"<<endl;
cin>>money;

cout<<"Enter an annual interest rate"<<endl;
cin>>interest;

cout<<"Enter how many years you want calculated"<<endl;
cin>>year;

do
{
money+=(money*(interest/100));
C++;
}
while (C<year);

cout<<money<<endl;

return 0;
}
Please use code format tags (in the palette on the right) to format your code.

To build the table, you're expected to write the result for each year, even though that is not stated.

Play around with the suggested format functions and see what effect they have on your output. For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream> // declares cout, endl
#include <iomanip>  // declares setw, setprecision, fixed

int main()
{
    using namespace std;

    double money = 1789.76;

    // experiment with some output
    std::cout << money << endl;
    cout << setprecision(2) << money << endl;
    cout << setprecision(12) << money << endl;
    cout << setw(12) << setprecision(12) << money << endl;

    // set field width
    int width = 8;

    // draw header
    for (int i = 0; i < width + 2; ++i)
        cout << "-";
    cout << endl;

    // write row
    cout << '|' << setw(width) << setprecision(12) << money << '|' << endl;

    // draw footer
    for (int i = 0; i < width + 2; ++i)
        cout << "-";
    cout << endl;
}
Topic archived. No new replies allowed.