Help with an Assignment(newb help)

I

isaac2004

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.
 
J

Jim Langston

isaac2004 said:
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?
 
I

isaac2004

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
 
J

Jim Langston

isaac2004 said:
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.
 
G

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.

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/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top