This should be solved in the interest.cpp file. Write a function declaration for
ID: 3693620 • Letter: T
Question
This should be solved in the interest.cpp file. 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 number of months for which interest must be paid. Inputs should be of type double, except that the number of months should be of type integer. 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 computed using this larger balance. Your function must use a loop structure to compute the total interest due. Embed this 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. Your program must use a function to compute the total interest due. A program which does not use a function will be awarded a score of zero, even if all tests pass. The program should print a string of text to the terminal before getting each piece of input from the user. A session should look like the following example (including whitespace and formatting), with possibly different inputs and numbers m the output: If any of the inputs is negative, then instead of outputting the interest due, the program should output the following before restarting the calculation: Each string printed by the program should include a newline at the end, but no other trailing whitespace (whitespace at the end of the line). The interest due must be displayed to exactly two digits after the decimal point.Explanation / Answer
#include<iostream>
#include <iomanip>
#include<cmath>
using namespace std;
double interest (double a, double b, int c)
{
double j=0.0;
if((a<0)||(b<0)||(c<0))
{
cout<<"Not a valid input";
return 0;
}
else
{
j=a*pow((1+b/100),c)-a;
return j;
}
}
int main()
{
double p,r,it;
int t;
do
{
cout<<" Enter the intial balance (or zero to quit): ";
cin>>p;
if(p==0)
break;
cout<<"Enter the monthly interest rate in percentage : ";
cin>>r;
cout<<"Enter the number of months : ";
cin>>t;
it=interest (p,r,t);
if(it!=0)
cout<<setprecision (2) << fixed <<"The interest due is "<<it<<".";
}while (1);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.