Velocity Reviews > C++ > Help with an Assignment(newb help)

# Help with an Assignment(newb help)

isaac2004
Guest
Posts: n/a

 10-03-2007
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.

Jim Langston
Guest
Posts: n/a

 10-04-2007
"isaac2004" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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?

isaac2004
Guest
Posts: n/a

 10-04-2007
On Oct 3, 8:08 pm, "Jim Langston" <(E-Mail Removed)> wrote:
> "isaac2004" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) oups.com...
>
>
>
> > 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

Jim Langston
Guest
Posts: n/a

 10-04-2007
"isaac2004" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> On Oct 3, 8:08 pm, "Jim Langston" <(E-Mail Removed)> wrote:
>> "isaac2004" <(E-Mail Removed)> wrote in message
>>
>> news:(E-Mail Removed) oups.com...
>>
>>
>>
>> > 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.

=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
Guest
Posts: n/a

 10-04-2007
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

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post The Martian Digital Photography 14 06-20-2008 07:56 AM =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?= ASP .Net 4 03-09-2006 12:46 PM Harvey ASP .Net 1 07-16-2004 01:12 PM Harvey ASP .Net 0 07-16-2004 10:00 AM =?Utf-8?B?dHJlbGxvdzQyMg==?= ASP .Net 0 02-20-2004 05:16 PM

Advertisments