Amortization Table

This is a discussion on Amortization Table within the C++ Programming forums, part of the General Programming Boards category; Hello, I have written code to calculate monthly payment for a loan. Now, I have to display an amortization table, ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    3

    Smile Amortization Table

    Hello,

    I have written code to calculate monthly payment for a loan. Now, I have to display an amortization table, which I don't know how to do. I have posted what I have written so far. Any help will be greatly appreciated. Thanks!

    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <math.h>
    using namespace std;
    
    int main ()
    
    {
    	//Stores variables
    	int loan_amount;
    	double interest_rate;
    	int loan_length;
    	double monthly_payment;
    	
    	//Prompts for and reads loan amount
    	cout << "Enter the amount of the loan: ";
    	cin >> loan_amount;
    	cout << endl;
    
    	//Prompts for and reads interest rate
    	cout << "Enter the Annual Interest Rate: ";
    	cin >> interest_rate;
    	cout << endl;
    
    	//Prompts for and reads loan length
    	cout << "Please enter the length of the loan in years: ";
    	cin >> loan_length;
    	cout << endl;
    
    	//Calculate monthly payment
    	interest_rate = interest_rate / 1200;
    	monthly_payment = (interest_rate + (interest_rate/(pow (1+interest_rate, 12*loan_length)-1))) * loan_amount;
    	
    	//Format output
    	cout << setprecision(2) << fixed << showpoint;
    
    	//Display monthly payment
    	cout << "The monthly payment is " << monthly_payment << endl << endl;
    
    //Display amortization table
    
    
    
    }

  2. #2
    Kung Fu Kitty Angus's Avatar
    Join Date
    Oct 2008
    Location
    Montreal, Canada
    Posts
    115
    I'm not sure exactly what your problem is. I'm not certain how to display an amortization table either, but that problem is a matter of accounting, not computer programming.
    If your problem is not knowing how to format your output, that's something else. I don't know if IOstreams is good for formatted output (although IMO IOstreams isn't good for anything, so I don't use it) so I'd use the ANSI C *printf() family of function. Whatever you decide to do, you should probably not mix your use of IOstreams and *printf()s, which means you should take out all your couts and replace them w/printf()s.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Now, I have to display an amortization table, which I don't know how to do
    Here is the pseudo code to display your amortization table. This is based on the code that you posted:

    LOOP THE FOLLOWING CODE FOR TOTAL MONTHS OF LOAN

    MONTHLY INTEREST PAID EQUAL TO AMOUNT OF LOAN TIMES INTEREST RATE
    MONTHLY PRINCIPAL PAID EQUAL TO MONTHLY PAYMENT MINUS MONTHLY INTEREST PAID
    LOAN BALANCE EQUAL TO LOAN AMOUNT MINUS MONTHLY PRINCIPAL PAID
    IF LOAN BALANCE LESS THAN ZERO THEN LOAN BALANCE EQUAL ZERO
    LOAN AMOUNT = LOAN BALANCE
    PRINT THE LOAN BALANCE AND PRINT THE MONTHLY INTEREST PAID

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    iostreams are very useful and are very good for a lot of things. Recommending that someone not use C++, and instead use C is very odd i think. There is nothing wrong with iostreams and in the majority of cases have the same performance, so really it is preference.

    Also, I do not see why it is bad to mix iostreams with printf() or whatever. They are places where one may make more since than the other.
    One bonus to iostreams is that they can be extended to do a vast amount of things, while printf() and all similar are not quite so simple to extend. Take for example making a fwrite() function that outputs a particular class. You either to to convert your class to something that fwrite can understand or re-make the fwrite() function. While with iostream you can overload the operator<<() and operator>>() to be able to handle all iostreams. Whether it be file/console input/output.

    I will stop ranting, but why recommend something that is more complicated, and has no apparent advantages over the C++ version.

  5. #5
    Kung Fu Kitty Angus's Avatar
    Join Date
    Oct 2008
    Location
    Montreal, Canada
    Posts
    115
    Quote Originally Posted by Raigne View Post
    iostreams are very useful and are very good for a lot of things. Recommending that someone not use C++, and instead use C is very odd i think. There is nothing wrong with iostreams and in the majority of cases have the same performance, so really it is preference.

    Also, I do not see why it is bad to mix iostreams with printf() or whatever. They are places where one may make more since than the other.
    *printf() buffers, and so does iostreams. If you write to both, you might find that when the descriptors flush, your data is out of order.

    I will stop ranting, but why recommend something that is more complicated, and has no apparent advantages over the C++ version.
    One problem I had is that when developing a CGI was if I sent something to cerr each character showed up as its own entry in the error log. This may not have been iostreams's fault, (although, it did make me wonder about its performance) but it made it unsuitable for this application. I don't remember exactly what other problems I had, but I found it unpredictable and frustrating. Iostreams might be a simpler to use for simple applications, but I found that I was just as happy using ANSI C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 06:06 PM
  2. progarm doesnt compile
    By kashifk in forum Linux Programming
    Replies: 2
    Last Post: 10-25-2003, 06:54 PM
  3. extra word printing
    By kashifk in forum C++ Programming
    Replies: 2
    Last Post: 10-25-2003, 05:03 PM
  4. inputting words from a file
    By kashifk in forum C++ Programming
    Replies: 5
    Last Post: 10-24-2003, 08:18 AM
  5. help with operator <
    By kashifk in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2003, 04:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21