Your function will receive, as input, the following information: The principle P
ID: 3688991 • Letter: Y
Question
Your function will receive, as input, the following information: The principle P, the amount of money loaned to you. This will be given to you as a non-negative long integer representing the number of cents in the principle. This is the initial balance B of the account before any payments are made or interest accrued. The annual interest rate, I, a floating point (double) number in the range 0.0 to 1.0. The monthly payment, M, a non-negative long integer representing the number of cents paid each month. Your function should carry out the following calculation for repeated months: Compute the month’s interest as the balance B times the interest rate divided by 12, rounded to the nearest penny. If the month’s interest exceeds or equals the monthly payment, the calculation is terminated because the loan will never be paid off. In that case, the program should produce a single output line This loan will never be paid off. Add the interest to and subtract a monthly payment from the balance. The above steps should be repeated until the loan is entirely paid off (the balance becomes zero). Note that the final payment may be less than the normal monthly payment if it exceeds the remaining balance. As you carry out the above steps, you should count the number of payments made (i.e., the number of months required to pay off the loan) and the total amount paid, keeping in mind the possibility that the final payment will be smaller than the rest. If, in fact, the loan is paid off, your program should produce a single line of output: The loan was paid off after Y years and M months for a total of $D.C where 0 <= M < 12 and 0 <= C < 100. C will always be printed as two digits, so if C is less than 10, a leading zero should be added to its output.
Here is my attemp:
while(p>0)
{
count++;
monthInt = B * (interest/12);
if (monthInt>=m)
{
cout << "Loan will never be paid off" << endl;
break;
}
else if(m>monthInt)
{
p = B+monthInt;
}
B = p-m;
cout << B << setprecision(2)<< endl;
}
Explanation / Answer
#include #include class account { char cust_name[20]; int acc_no; char acc_type[20]; public: void get_accinfo() { coutcust_name; coutacc_no; coutacc_type; } void display_accinfo() { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.