Hey, i got some previous help with this program i had to write for a school assignment.

The problem was assigned as follows:

"Write a program that calculates the balance of a savings account at the end of a three-month period. It should ask the user for the starting balance and the annual interest rate. A loop should then iterate once for every month in the period, performing the following:
A. Ask the user for the total amount deposited into the account during that month. Do not accept negative numbers. This amount should be added to the balance.
B. Ask the user for the total amount withdrawn from the account during that month. Do not accept negative numbers or numbers greater than the balance after the deposits for that month have been added in.
C. Calculate the interest for that month. The monthly interest rate is the annual interest rate divided by 12. Multiply the monthly interest rate by the balance to get the interest amount for the month. This amount should be added to the balance.
After the last iteration, the program should display a final report that includes the following information:
starting balance at the beginning of the three-month period.
total deposits made during the three months
total withdrawals made during the three months
total interest posted to the account during the three months
final balance."

Here is my code I have thus far:

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
int startingBalance = 0, annualRate = 0, monthlyRate = 0, totalAmount = 0, currentAmount = 0, currentWithdrawn = 0, currentInterestAmount = 0;
int startingBalanceArray[3], endingBalanceArray[3];
	cout << "Please enter your starting balance: ";
	cin >> startingBalance;
	cout << "Please enter your annual interest rate: ";
	cin >> annualRate;
	totalAmount = startingBalance;
	monthlyRate = annualRate / 12;

for(int month=1; month<=3; month++)
{
     do {
     startingBalanceArray[month] = totalAmount;
     cout << "Please enter the amount deposited in month " << month << " : ";
     cin >> currentAmount;
     if (currentAmount > 0)
	{
			 totalAmount += currentAmount;
		}
		else
		{
			cout<< endl << "Please enter an amount greater than 0." << endl;
		}
    }
	while (currentAmount<0);

    do
	{
		cout << "Please enter the amount withdrawn in month "<< month << " : ";
		cin >> currentWithdrawn;
	if(currentWithdrawn > 0 && currentWithdrawn < totalAmount)
		{
			totalAmount -= currentWithdrawn;
		}
    else
		{
			cout << "Please enter an amount between 0 and " << totalAmount << endl;
		}
     }
	 while (currentAmount < 0 || currentWithdrawn > totalAmount);
     endingBalanceArray[month] = totalAmount;
     currentInterestAmount =(endingBalanceArray[month] - startingBalanceArray[month]) * monthlyRate;
     totalAmount += currentInterestAmount;
}

     cout << endl<< "Startng balance = " << startingBalance << endl;
	 cout << "The total deposits made in the 3 months = " << startingBalanceArray[3] << endl;
	 cout << "The total withdrawals made in the 3 months = " << endl;
	 cout << "The total interest posted to the account during the 3 months = " << endl;
	 cout << "Total amount in the account after 3 months = " << totalAmount;

	_getch();
	return 0;

}

My program runs fine, I just don't know how to display the total deposits, total withdrawals, and the total interest posted in the three months.

Any help would be good help!

Thanks

You need to declare totalDeposit, totalWithdraw, and totalInterest outside the loop and initiated them to 0. Then inside the loop, each time you do a deposit, add the amount to totalDeposit. Do the same with totalWithdraw. Now, the totalInterest is added with the currentInterestAmount. After that, you can display these variables in wherever you want outside the loop (where your cout are).

You need to declare totalDeposit, totalWithdraw, and totalInterest outside the loop and initiated them to 0. Then inside the loop, each time you do a deposit, add the amount to totalDeposit. Do the same with totalWithdraw. Now, the totalInterest is added with the currentInterestAmount. After that, you can display these variables in wherever you want outside the loop (where your cout are).

Thanks! I actually figured it out using a much simpler method with only one while loop instead of arrays. But this helps indeed.:)

what is the fortran code for this program pleae

Comments
Avoid dredging up old posts like this. Make your new post showing your work so far. I coded in Fortran IV long ago.
This article has been dead for over six months. Start a new discussion instead.