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

Can someone show me what I am doing wrong my C++ code the calculations are worng

ID: 3665623 • Letter: C

Question

Can someone show me what I am doing wrong my C++ code the calculations are worng.

Here is the question:

Write a function declaration for a function that computes interest on a credit card account balace. The function takes arguments for the intitial balance, the monthly intrest rate, and the number of months for which interest must be paid. The vakue returned is the interest due. Do not forget to compound the interst-that is, to charge inteest on the interest due. The interest due is added to the balance due, and the interest and interest for the next month is computed 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:

A Loop Body with Several Statements:

do

{

                Statement_1

                Statement_2

                …

                Statement_Last

} while (Boolean _Expression);

A Loop Body with a Single Statement:

do

                Statement

while (Boolean_Expression);

Embed the function in a progrsm that reads the value for the interest rate, initial account balance, and number of months, then out puts 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.

Here is my code:

#include<iostream>
using namespace std;

// Function definition
double interest (double , double , int );

int main()
{
// Decleration of veriables.
    double Balance, interestRate, total;
    int months;
    char choice;

    do
    {

// Inputting data that needs to be calculated.
        cout<<"Credit card interest."<<endl;
        cout<<"Enter doubles: initial balance, monthly interest rate as"<<endl;
        cout<<"a decimal faction, e.g. for 1.5% per month write 0.015"<<endl;
        cout<<"and int months the bill has run."<<endl;
        cout<<"I will give you the interest that has accumulated."<<endl;
        cin>>Balance;
        cin>>interestRate;    
        cin>>months;
    
// Call the function.
        total=interest(Balance, interestRate, months);
// Outputting interest.
        cout<<"Interest accumulated = : "<<total<<endl;
// Input chice to repeat.
        cout<<"Y or y repeats, any other character quits.";
        cin>>choice;    
    }
    while(choice == 'y' || choice == 'Y');
// Pause system for a while
   // system("pause");    
}

// Function definition
    double interest (double intitialBalance, double interestRate, int months)
    {

        double initialBalance;
        double total = 0;
        int i;
        for (i = months; i>=0; i--)
        {
            total += ((initialBalance * interestRate)/(100 *12));
            initialBalance += ((initialBalance *(100+interestRate))/(100 *12));
        }
        return total;
    }

The output should look like this:

Credit card interest

Enter doubles: initial balance, monthly interest rate as

a decimal fraction, e.g. for 1.5% per month write 0.015

and int months the bill fas run.

I will give you the interest that has accumulated.

1000

0.015

121

Interest accumulated = $195.62 (here is my problem my output reads 0)

Y or y repeats, any other character quits

Explanation / Answer

Sharing the Pseudo code for reference.

This function can be declared like this:

// ============================================================================
// Function:   interest
// Description:   This function calculates the total credit card interest based
//       on your initial balance, interest, rate and months
//
// Parameter:
// initBalance [IN] -- an double value of initial balance received
// rate [IN] -- an double value of interest rate like 0.02 as 2%
// months [IN] -- the number of months of the integer type
//
// Return:
// An double value of the final interest amount calculated
// ============================================================================
double interest(double initBalance, double rate, int months);

// The algorithm:
// declare variable: balance = initBalance
// initialize variable i = 0 to represent month increment
// repetition to update balance by computing compound credit card interest
// Hint: ref to DISPLAY 2.15 Charge Card Program in Chapter 2   
// the interest returned should be balance - initBalance
This function is to be called in main() that acquires these values and outputs the interest due.

The following is an algorithm in pseudocode:
1. declare balance, rate, interestEarned, months
2. repeat the following actions until exit:
(1). fetch balance, rate, months
(2). interestEarned = interest(balance, rate, months)
(3). output interestEarned

Try the below Code for reference:

#include <iostream>

using namespace std;

int main ( )

{

int months, count = 1;

double init_Balance, rate, interest = 0, new_balance, total_Interest = 0, int_Accumulated;

char repeats;

do

{

total_Interest = 0;

{

cout << " Credit card interest ";

cout << "Enter: Initial balance, monthly interest rate as a decimal fraction, e.g. for 1.5&#37; per month write 0.015, and the number of months the bill has run. ";

cout << "I will give you the interest that has accumulated. ";

cin >> init_Balance >> rate >> months;

}

for ( int count = 0; count < months; count++)

{

interest = ( rate * init_Balance );

new_balance = ( init_Balance + interest );

total_Interest = ( interest + );

cout << count ++;

}

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(2);

{

cout << "Interest accumulated = $ ";

cin >> int_Accumulated;

cout << "Y or y repeats, any other character quits. ";

}

}while ( repeats != 'Y' && repeats != 'y' );

return 0;

}