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 will not complie. Here is

ID: 3664951 • Letter: C

Question

Can someone show me what I am doing wrong my C++ code will not complie.

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 nterest rate.
       cout<<"Enter interest rate: ";
       cin>>interestRate;
// Inputting balance.
       cout<<"Enter initial balance: ";
       cin>>Balance;
// Inputting number of months.
       cout<<"Enter number of months: ";
       cin>>months;
      
// Call the function.
       total=interest(Balance, interestRate, months);
// Outputting interest.
       cout<<"Interest due : "<<total<<endl;
// Input chice to repeat.
       cout<<"If you want to repeat caculations press 'y'";
       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 total = 0;
       for (int i = months; i>0; i--)
       {
           total += ((intitialBalance * interestRate)/(100 *12));
           initialBalance += ((initialBalance *(100+interestRate))/100 *12));
       }
   }
       }
       return total;
}

Explanation / Answer

Here The Correct Code is

#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 balance.
        cout<<"Enter initial balance: "<<endl;
        cin>>Balance;
// Inputting nterest rate.
        cout<<"Enter interest rate: "<<endl;
        cin>>interestRate;      
// Inputting number of months.
        cout<<"Enter number of months: "<<endl;
        cin>>months;
      
// Call the function.
        total=interest(Balance, interestRate, months);
// Outputting interest.
        cout<<"Interest due : "<<total<<endl;
// Input chice to repeat.
        cout<<"If you want to repeat caculations press 'y'";
        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 += ((intitialBalance * interestRate)/(100 *12));
            initialBalance += ((initialBalance *(100+interestRate))/(100 *12));
        }
        return total;
    }