//This program reads the principal amount in an accout, the monthly interest rate and the amount withdrawn per month from a file.
//It then computes the number of years before the account is depleted.
//If the account will not deplete it displays a message informing the user.
//It continues until values of 0, 0, 0 are entered.
#include <iostream>
#include <conio.h>
#include <fstream>
using namespace std;
#define in_file "assignment1.txt"
#define out_file "resultassign1.txt"
int main()
{
ifstream ins;
ofstream outs;
double principal, yearly_rate, monthly_rate, monthly_withdrawal, new_principal, number_months, N;
ins.open(in_file);
outs.open(out_file);
ins >> principal >> yearly_rate >> monthly_withdrawal;
monthly_rate=yearly_rate/12;
while (principal !=0 || monthly_rate !=0 || monthly_withdrawal !=0)
{
N=0;
new_principal=(principal*(1+monthly_rate))-monthly_withdrawal;
if(new_principal>=principal)
cout << "The account will never be depleted!" << endl;
else
new_principal=principal;
number_months=N++;
if(new_principal <=0)
cout << "The number of years before the account is depleted is: " << N;
ins >> principal >> yearly_rate >> monthly_withdrawal;
}
ins.close();
outs.close();
getch();
return 0;
}
A sample input:
10000 0.06 500
0 0 0
Need help with the nested if's and incrementing variables.
This post has been edited by DanFurgason: 30 January 2011 - 05:15 PM

New Topic/Question
Reply



MultiQuote



|