Answer:
#include <iostream>
#include <fstream>
 using namespace std;
int main() {
// Definitions
        double annualInterest;          // The annual interest rate
        double balance;                 // The account balance
        int months;                     // Total number of months
        double totalDeposit  = 0.0;     // Total deposited value
        double totalWithdraw = 0.0;     // Total withdrawn value
        double earnedInterest= 0.0;     // The earned amount
        double deposited;               // Monthly deposited value
        double withdrawn;               // Monthly withdrawn value
// Get the initial required data.
        
        cout<<"Please enter the annual interest rate,\n";
        cout<<"   Interest rate: ";
        cin >>annualInterest;
        cout<<"--------------------------------------------\n";
        cout<<"Please enter the starting balance,\n";
        do{
            cout<<"[the number could not be negative]\n";
            cout<<"Starting Balance: ";
            cin >>balance;
        }while(balance<0);
        cout<<"--------------------------------------------\n";
        cout<<"Please enter the number of months,\n";
        do{
            cout<<"[the number could not be less than 0]\n";
            cout<<"Number of months: ";
            cin >>months;
        }while(months<0);
// Iterated Loop to get all the months data.
        for(int month=1; month <= months; month++){
// Get the deposited value during that month.
            cout<<"Enter the deposited value during month "
                <<month<<",\n";
            do{
                cout<<"[the value could not be less than 0]\n";
                cout<<" Deposited value: ";
                cin >>deposited;
            }while(deposited<0);
            
            totalDeposit += deposited;
            balance += deposited;
// Get the withdrawn value during that month.
            cout<<"Enter the withdrawn value during month "
                <<month<<",\n";
            do{
                cout<<"[the value could not be less than 0]\n";
                cout<<" Withdrawn value: ";
                cin >>withdrawn;
            }while(withdrawn<0);
            
            totalWithdraw += withdrawn;
            balance -= withdrawn;
// Negative balance close the program.
            if(balance < 0){
                cout<<"Sorry, the account has been closed due to\n";
                cout<<"the negative balance.\n";
                  break;
// Calculate value due to the interest rate.
            } 
       else {
                earnedInterest += (annualInterest/12) * balance;
                //        monthly interest rate
                balance += (annualInterest/12) * balance;
            }
        }
   // Display the statistics,
       ofstream file;
       file.open ("Report written to Report.txt");
       file << "Report written to Report.txt\n";
        file.close();
        cout<<"The ending balance: "<<balance<<std::endl;
        cout<<"   Total deposited: "<< totalDeposit<<std::endl;
        cout<<" Total withdrawals: "<< totalWithdraw<<std::endl;
        cout<<"   Earned interest: "<< earnedInterest<<std::endl;
        cout<<"============================================\n";
  return 0;
    }