Help with an Assignment(newb help)

Discussion in 'C++' started by isaac2004, Oct 4, 2007.

  1. isaac2004

    isaac2004 Guest

    hello to all. i am in a Introductory C++ class and I have been having
    some issue with an assignment that i was given. Here is a brief setup
    for it.

    Write a program to print out a loan repayment schedule. The input is
    the loan amount, the annual percentage rate and the monthly payments.
    If the monthly payment will not pay off the loan, print an error
    message and quit.For each payment, it is first is used to pay the
    month's interest on the outstanding debt. This would be 1/12 of the
    yearly interest at the annual percentage rate. After the interest is
    paid, the remaining payment is applied to the debt, reducing the
    outstanding debt. The last month many not need a full payment. After
    printing the schedule, print a summary of the loan. This should
    include the initial loan amount, the rate, the monthly payment, the
    number of payments, total interest paid and total paid.


    A possible out put can be the following for input of 100, 60, 20

    month principle interest
    --------------------------
    1 100.00 5.00
    2 85.00 4.25
    3 69.25 3.46
    4 52.71 2.63
    5 35.34 1.76
    6 17.10 .85

    Principle: $100
    Rate: 60%
    5 payments of $20, last payment of 17.95
    Total interest paid: $17.95
    Total repaied: $117.95

    I have been wrestling with this for a couple of days on how to do
    this. The initial input is easy but its the actual algorithm of the
    computing and storing that I am having an issue with, that is could i
    store each individual payment into an array of records or something
    like that. I know the loop must be set up like.

    while (principle >0) { do stuff }

    its the do stuff that I am getting stuck on. Can I have any ideas for
    how to do this.
    NO CODE PLEASE!!! I would like to learn this for myself. Thank you
    before hand.
    isaac2004, Oct 4, 2007
    #1
    1. Advertising

  2. isaac2004

    Jim Langston Guest

    "isaac2004" <> wrote in message
    news:...
    > hello to all. i am in a Introductory C++ class and I have been having
    > some issue with an assignment that i was given. Here is a brief setup
    > for it.
    >
    > Write a program to print out a loan repayment schedule. The input is
    > the loan amount, the annual percentage rate and the monthly payments.
    > If the monthly payment will not pay off the loan, print an error
    > message and quit.For each payment, it is first is used to pay the
    > month's interest on the outstanding debt. This would be 1/12 of the
    > yearly interest at the annual percentage rate. After the interest is
    > paid, the remaining payment is applied to the debt, reducing the
    > outstanding debt. The last month many not need a full payment. After
    > printing the schedule, print a summary of the loan. This should
    > include the initial loan amount, the rate, the monthly payment, the
    > number of payments, total interest paid and total paid.
    >
    >
    > A possible out put can be the following for input of 100, 60, 20
    >
    > month principle interest
    > --------------------------
    > 1 100.00 5.00
    > 2 85.00 4.25
    > 3 69.25 3.46
    > 4 52.71 2.63
    > 5 35.34 1.76
    > 6 17.10 .85
    >
    > Principle: $100
    > Rate: 60%
    > 5 payments of $20, last payment of 17.95
    > Total interest paid: $17.95
    > Total repaied: $117.95
    >
    > I have been wrestling with this for a couple of days on how to do
    > this. The initial input is easy but its the actual algorithm of the
    > computing and storing that I am having an issue with, that is could i
    > store each individual payment into an array of records or something
    > like that. I know the loop must be set up like.
    >
    > while (principle >0) { do stuff }
    >
    > its the do stuff that I am getting stuck on. Can I have any ideas for
    > how to do this.
    > NO CODE PLEASE!!! I would like to learn this for myself. Thank you
    > before hand.


    Consider: After you print out each payment, you no longer need to keep the
    information on that payment, only what the balance (principal) is to
    calculate the next months principle.

    I don't want to do your homework for you, and your actual homework
    assignment is for you to figure out exactly how to do this, so I'll try
    something similar, but dufferent.

    Say we start with X amount, and each time half it. How long until it
    reaches 1? Would be rather simple (not doing error checking etc.. and
    untested code)

    double x;
    std::cout << "Enter initial amount: ";
    std::cin >> x;

    while ( x > 1.0 )
    {
    x = x / 2;
    std::cout >> x << "\n";
    }

    So if we orignally input 10 the output woudl be:
    5
    2.5
    1.25
    0.75

    Notice I didn't have to keep track of how much the previous amount was, only
    what the current amount is. You need to do the same in your program.

    Incidently, x = x / 2 could also be written as x /= 2, x = x * 0.5 or x *=
    0.5; There is sometimes more than one way to do a formula in C and C++.

    Does this help any?
    Jim Langston, Oct 4, 2007
    #2
    1. Advertising

  3. isaac2004

    isaac2004 Guest

    On Oct 3, 8:08 pm, "Jim Langston" <> wrote:
    > "isaac2004" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > hello to all. i am in a Introductory C++ class and I have been having
    > > some issue with an assignment that i was given. Here is a brief setup
    > > for it.

    >
    > > Write a program to print out a loan repayment schedule. The input is
    > > the loan amount, the annual percentage rate and the monthly payments.
    > > If the monthly payment will not pay off the loan, print an error
    > > message and quit.For each payment, it is first is used to pay the
    > > month's interest on the outstanding debt. This would be 1/12 of the
    > > yearly interest at the annual percentage rate. After the interest is
    > > paid, the remaining payment is applied to the debt, reducing the
    > > outstanding debt. The last month many not need a full payment. After
    > > printing the schedule, print a summary of the loan. This should
    > > include the initial loan amount, the rate, the monthly payment, the
    > > number of payments, total interest paid and total paid.

    >
    > > A possible out put can be the following for input of 100, 60, 20

    >
    > > month principle interest
    > > --------------------------
    > > 1 100.00 5.00
    > > 2 85.00 4.25
    > > 3 69.25 3.46
    > > 4 52.71 2.63
    > > 5 35.34 1.76
    > > 6 17.10 .85

    >
    > > Principle: $100
    > > Rate: 60%
    > > 5 payments of $20, last payment of 17.95
    > > Total interest paid: $17.95
    > > Total repaied: $117.95

    >
    > > I have been wrestling with this for a couple of days on how to do
    > > this. The initial input is easy but its the actual algorithm of the
    > > computing and storing that I am having an issue with, that is could i
    > > store each individual payment into an array of records or something
    > > like that. I know the loop must be set up like.

    >
    > > while (principle >0) { do stuff }

    >
    > > its the do stuff that I am getting stuck on. Can I have any ideas for
    > > how to do this.
    > > NO CODE PLEASE!!! I would like to learn this for myself. Thank you
    > > before hand.

    >
    > Consider: After you print out each payment, you no longer need to keep the
    > information on that payment, only what the balance (principal) is to
    > calculate the next months principle.
    >
    > I don't want to do your homework for you, and your actual homework
    > assignment is for you to figure out exactly how to do this, so I'll try
    > something similar, but dufferent.
    >
    > Say we start with X amount, and each time half it. How long until it
    > reaches 1? Would be rather simple (not doing error checking etc.. and
    > untested code)
    >
    > double x;
    > std::cout << "Enter initial amount: ";
    > std::cin >> x;
    >
    > while ( x > 1.0 )
    > {
    > x = x / 2;
    > std::cout >> x << "\n";
    >
    > }
    >
    > So if we orignally input 10 the output woudl be:
    > 5
    > 2.5
    > 1.25
    > 0.75
    >
    > Notice I didn't have to keep track of how much the previous amount was, only
    > what the current amount is. You need to do the same in your program.
    >
    > Incidently, x = x / 2 could also be written as x /= 2, x = x * 0.5 or x *=
    > 0.5; There is sometimes more than one way to do a formula in C and C++.
    >
    > Does this help any?


    yes thanks, but the main problem i am catching is the error. if i do
    it in a cout statement, how do i check if the final product is going
    to work. notice the error

    If the monthly payment will not pay off the loan, print an error
    message and quit.

    thanks for the help so far
    isaac2004, Oct 4, 2007
    #3
  4. isaac2004

    Jim Langston Guest

    "isaac2004" <> wrote in message
    news:...
    > On Oct 3, 8:08 pm, "Jim Langston" <> wrote:
    >> "isaac2004" <> wrote in message
    >>
    >> news:...
    >>
    >>
    >>
    >> > hello to all. i am in a Introductory C++ class and I have been having
    >> > some issue with an assignment that i was given. Here is a brief setup
    >> > for it.

    >>
    >> > Write a program to print out a loan repayment schedule. The input is
    >> > the loan amount, the annual percentage rate and the monthly payments.
    >> > If the monthly payment will not pay off the loan, print an error
    >> > message and quit.For each payment, it is first is used to pay the
    >> > month's interest on the outstanding debt. This would be 1/12 of the
    >> > yearly interest at the annual percentage rate. After the interest is
    >> > paid, the remaining payment is applied to the debt, reducing the
    >> > outstanding debt. The last month many not need a full payment. After
    >> > printing the schedule, print a summary of the loan. This should
    >> > include the initial loan amount, the rate, the monthly payment, the
    >> > number of payments, total interest paid and total paid.

    >>
    >> > A possible out put can be the following for input of 100, 60, 20

    >>
    >> > month principle interest
    >> > --------------------------
    >> > 1 100.00 5.00
    >> > 2 85.00 4.25
    >> > 3 69.25 3.46
    >> > 4 52.71 2.63
    >> > 5 35.34 1.76
    >> > 6 17.10 .85

    >>
    >> > Principle: $100
    >> > Rate: 60%
    >> > 5 payments of $20, last payment of 17.95
    >> > Total interest paid: $17.95
    >> > Total repaied: $117.95

    >>
    >> > I have been wrestling with this for a couple of days on how to do
    >> > this. The initial input is easy but its the actual algorithm of the
    >> > computing and storing that I am having an issue with, that is could i
    >> > store each individual payment into an array of records or something
    >> > like that. I know the loop must be set up like.

    >>
    >> > while (principle >0) { do stuff }

    >>
    >> > its the do stuff that I am getting stuck on. Can I have any ideas for
    >> > how to do this.
    >> > NO CODE PLEASE!!! I would like to learn this for myself. Thank you
    >> > before hand.

    >>
    >> Consider: After you print out each payment, you no longer need to keep
    >> the
    >> information on that payment, only what the balance (principal) is to
    >> calculate the next months principle.
    >>
    >> I don't want to do your homework for you, and your actual homework
    >> assignment is for you to figure out exactly how to do this, so I'll try
    >> something similar, but dufferent.
    >>
    >> Say we start with X amount, and each time half it. How long until it
    >> reaches 1? Would be rather simple (not doing error checking etc.. and
    >> untested code)
    >>
    >> double x;
    >> std::cout << "Enter initial amount: ";
    >> std::cin >> x;
    >>
    >> while ( x > 1.0 )
    >> {
    >> x = x / 2;
    >> std::cout >> x << "\n";
    >>
    >> }
    >>
    >> So if we orignally input 10 the output woudl be:
    >> 5
    >> 2.5
    >> 1.25
    >> 0.75
    >>
    >> Notice I didn't have to keep track of how much the previous amount was,
    >> only
    >> what the current amount is. You need to do the same in your program.
    >>
    >> Incidently, x = x / 2 could also be written as x /= 2, x = x * 0.5 or x
    >> *=
    >> 0.5; There is sometimes more than one way to do a formula in C and C++.
    >>
    >> Does this help any?

    >
    > yes thanks, but the main problem i am catching is the error. if i do
    > it in a cout statement, how do i check if the final product is going
    > to work. notice the error
    >
    > If the monthly payment will not pay off the loan, print an error
    > message and quit.
    >
    > thanks for the help so far


    That's easy. If the monthly payment is less than the first months interest,
    then the payment will never pay off the loan. If the payment is greater
    than the first months interest, then it will pay off the loan. The reason
    is for the loan to eventually be paid off, the principal has to go down.
    The principal only goes down if the payment is greater than the interst. So
    you only need to check once. If principal * ( yearly interest / 12 ) [which
    is the interest for first payment] is greater than payment, loan will never
    be paid off. Otherwise it will.
    Jim Langston, Oct 4, 2007
    #4
  5. On 2007-10-04 01:46, isaac2004 wrote:
    > hello to all. i am in a Introductory C++ class and I have been having
    > some issue with an assignment that i was given. Here is a brief setup
    > for it.
    >
    > Write a program to print out a loan repayment schedule. The input is
    > the loan amount, the annual percentage rate and the monthly payments.
    > If the monthly payment will not pay off the loan, print an error
    > message and quit.For each payment, it is first is used to pay the
    > month's interest on the outstanding debt. This would be 1/12 of the
    > yearly interest at the annual percentage rate. After the interest is
    > paid, the remaining payment is applied to the debt, reducing the
    > outstanding debt. The last month many not need a full payment. After
    > printing the schedule, print a summary of the loan. This should
    > include the initial loan amount, the rate, the monthly payment, the
    > number of payments, total interest paid and total paid.
    >
    >
    > A possible out put can be the following for input of 100, 60, 20
    >
    > month principle interest
    > --------------------------
    > 1 100.00 5.00
    > 2 85.00 4.25
    > 3 69.25 3.46
    > 4 52.71 2.63
    > 5 35.34 1.76
    > 6 17.10 .85
    >
    > Principle: $100
    > Rate: 60%
    > 5 payments of $20, last payment of 17.95
    > Total interest paid: $17.95
    > Total repaied: $117.95
    >
    > I have been wrestling with this for a couple of days on how to do
    > this. The initial input is easy but its the actual algorithm of the
    > computing and storing that I am having an issue with, that is could i
    > store each individual payment into an array of records or something
    > like that. I know the loop must be set up like.
    >
    > while (principle >0) { do stuff }
    >
    > its the do stuff that I am getting stuck on. Can I have any ideas for
    > how to do this.
    > NO CODE PLEASE!!! I would like to learn this for myself. Thank you
    > before hand.


    General questions on programming (i.e. those with no code) are better
    asked in comp.programming since they are off topic in here (the answer
    to your question is not specific for C++). When you later got a question
    about how to do something, this is the place. Please also read the FAQ,
    it has the answers to many questions and section 5 contains good advice
    for those new to usenet. The FAQ: http://www.parashift.com/c -faq-lite/

    --
    Erik Wikström
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Oct 4, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Prime

    Newb: Help with code !

    Prime, Jan 1, 2005, in forum: VHDL
    Replies:
    2
    Views:
    525
    Brad Smallridge
    Jan 2, 2005
  2. David K. Worman

    Perl newb in need of help with script.

    David K. Worman, Sep 18, 2003, in forum: Perl
    Replies:
    2
    Views:
    384
    David K. Worman
    Sep 18, 2003
  3. nagy
    Replies:
    36
    Views:
    986
    Terry Reedy
    Jul 20, 2006
  4. Chris
    Replies:
    34
    Views:
    1,489
  5. Andrew
    Replies:
    2
    Views:
    223
    Stephen Horne
    Sep 21, 2008
Loading...

Share This Page