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

C++ Coding (4-6 Please make code Copy and Paste-able , also this is an intro cla

ID: 3844511 • Letter: C

Question

C++ Coding (4-6 Please make code Copy and Paste-able, also this is an intro class so please nothing too advanced)

6. Write a function declaration for a function that computes interest on a credit card account balance. The function takes arguments for the initial balance, the monthly interest rate, and the numberof months for which interest must be paid. The value returned is the interest due. Do not forget to compound the interest-that is, to charge interest on the interest due. The interest due is added into the balance due, and the interest for the next month is com- puted using this larger balance. Use a while loop that is similar to (but need not be identical to) the one shown in Display 2.14. Embed the function in a program that reads the values for the interest rate, initial account balance, and number of months, then outputs the interest due. Embed your function definition in a program that lets the user compute interest due on a credit account balance. The program should allow the user to repeat the calculation until the user says he or she wants to end the program Below is an example showing the accumulation of interest with an initial balance of $100 and a 12% annual rate: num. Months one month int b. balance int rate end balance accrued int $100.00 12.00% $101.00 12.00% $2.01 $101.00 $1.01 $102.01 12.00% $103.03 $102.01 $3.03 $103.03 12.00% $1.03 $104.06 $4.06 12.00% $104.06 $1.04 $105.10 $5.10 12.00% $106.15 $6.15 $105.10 $1.05

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <cmath>
double calculateInt(double intB,double intR, int month);

using namespace std;

int main()
{
double intBalance, intRate, intDue; // variable declaration
int numOfMonth;// variable declaration
int ch= 0;
while(ch!=1)
{
cout << " Enter the initial balance: ";
cin >> intBalance;
cout << " Enter the Interest Rate(yearly in %) ";
cin >> intRate;
cout << " Enter the number of monthes for which interest must be paid ";
cin >> numOfMonth;

// the compound interest intDue would be an output data!

intRate/=100; // rate was expressed in percents! So,it has to be converted in decimal

intDue=calculateInt(intBalance,intRate,numOfMonth);
cout <<fixed << setprecision(2)<< " Total Interest: " << intDue << endl; // interest is an output data!
cout << fixed << setprecision(2)<<" End balance after the full time period " << intDue+intBalance << endl;

cout<<" if you want to quit the program press 1 else press any other number to continue ";
cin>>ch;
}

return 0;
}

double calculateInt(double intB,double intR, int month)
{
   // formula to calculate the compund total due is: Principal*(1+rate/n)^nt where n=12 for monthly compound t =number of year
   double totDue,totInterest;
   int n =12;
   double t=(double)month/n;
   double x=n*t;
   double r=(double)intR/n;
   double s=r+1;
   double pw=pow(s,x);
  
   totDue=intB*pw;
   //totDue=intB*(pow ((1+r),x));
  
   totInterest= totDue-intB;
   return totInterest;
}