Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Construct a C++ program that accepts an amount of money as a deposit and the num

ID: 3874133 • Letter: C

Question

Construct a C++ program that accepts an amount of money as a deposit and the number of years it has been deposited (years can have decimals). The program must determine the interest to be paid on the deposit based on the following schedule:

            Time on Deposit                                                   Interest Rate

            >= 5 years                                                                    4.5%

            Less than 5 and >=4 years                                            4%

            Less than 4 and >=3 years                                            3.5%

            Less than 3 and >=2 years                                            2.5%

            Less than 2 and >=1 years                                            2%

            Less than 1 year                                                           1.5%

The program must also compute the interest on the deposit using the formula: Interest = Deposit * IntRate * Years.

Furthermore it must also display the original deposit, the interest earned and the new Balance (with interest added to the deposit).

Please comment on every line of code.

Explanation / Answer

The code is

#include <iostream>
using namespace std;
int main()
{
float money;
cout<<"Enter the amount ";
cin>>money;//taking input and storing in money
cout<<"Enter the number of years ";
float years;
cin>>years;//taking input and storing in years
float rate;
//assigning rate value based on the years
if(years<1)
rate=1.5/100;
else if(years<2)
rate=2/100;
else if (years<3)
rate=2.5/100;
else if(years<4)
rate=3.5/100;
else if(years<5)
rate=4/100;
else
rate=5/100;
float interest=rate*money*years;//calculating interest
cout<<"The original deposit is "<<money<<endl;
cout<<"The Interest earned is "<<interest<<endl;
cout<<"The new balance is "<<money+interest<<endl;

}

The output is

Enter the amount 100
Enter the number of years 2
The original deposit is 100
The Interest earned is 5
The new balance is 105