I have this question. could anyone help me how to write C++ code for it:
A bank account starts out with $10,000. Interest is compounded monthly at 6% per year
(0.5% per month). Every month, $500 is withdrawn to meet college expenses. After how
many years is the account depleted?
Suppose the numbers ($10,000, 6%, $500) are inputs to the program. Are there values for
which the algorithm you developed would not terminate? If so, make sure you change
your algorithm such that it always terminates. If the account will not be depleted you
should output a message to the user saying that “Account will never be depleted!”.
The output from this program is the number of years the account is depleted. The
program should continue processing different sets of input data until (0,0,0) is entered by
the user.
here is a sample of input in file:
10000 6 500
20000 7 300
15000 5 700
9000 3 1000
5000 2 300
8000 12 70
0 0 0
This is what I've gotten so far, but it has many mistakes and i cannot fix it. please help asap and thanks in advance:
#include <iostream>; // requires for keyboard and screen I/O
#include <fstream>; // requires for external file streams
#include <cmath>; // used for mathematical operations
// Associating program identifiers with external file names
#define in_file "data.txt"
#define out_file "result.txt"
using namespace std;
void main()
{
ifstream ins; // associates ins as an input stream
ofstream outs; // associates outs as an output stream
// local values
float
originalAmount, monthlyInterest, yearlyInterest, balance, Expenses;
int Month, Year, Total, Time;
ins.open(in_file);
outs.open(out_file);
monthlyInterest = (yearlyInterest/12);
ins >> originalAmount;
while (originalAmount != -1) // read a number from file
{
// Calculate monthly payment.
Total = (monthlyInterest * originalAmount)- Expenses;
balance = (monthlyInterest * originalAmount);
Year = Month / 12;
Month = Month % 12;
Time = Year + Month;
cout << "The account will be depleted in" << Year << "year(s)and" << Month << "month(s)" << endl;
outs << "The account will be depleted in" << Year << "year(s)and" << Month << "month(s)" << endl;
ins >> originalAmount;
}
cout << "The originalAmount balance" << originalAmount << endl;
cout << "The yearly interest rate: " << yearlyInterest << endl;
cout << "Withdrawal expenses per month:" << Expenses << endl;
// press any key to exit
system("pause");
// end while loop
ins.close();
outs.close();
}// end program