Some help with this

D

Drakscon

Some one helped out but completely confused me. this is a senario so i
can take it into the actually program im using(variables a, b, c, d are
generic but i have commented about what they are for)


Im trying to get the compounded interest so that it will work for more
than just annually. I want the user of this program to be able to do
semi annually or monthly even some other defined by the user.

The formula i was given is balance = balance + (balance* (rate/100))


This is my code. Any input is welcome


int main()
{
double a,b,c,d;//a is amount to be invested, b is years
invested
//c is compound time, d is interest rate
char ch;//allows user to enter another investment
do{
system("cls");
cout<<"enter an ammount to invest ";
cin>>a;
cout<<"Enter the years to allow to mature ";
cin>>b;
cout<<"How many times a year will it be compounded? ";
cin>>c;
cout<<"What is the rate ";
cin>>d;


for(int i=0;i<b;i++){
for(int h=0;h<c;i++){
a=a+(a*(d/100));
}


}


cout<<"After "<<b<<" years. You have now "<<e<<"
dollars in the
account\n";


cout<<"Would you like to run another? ";
cin>>ch;
}while(ch=='y'||ch=='Y');


return 0;





}
 
H

Howard

Drakscon said:
Some one helped out but completely confused me. this is a senario so i
can take it into the actually program im using(variables a, b, c, d are
generic but i have commented about what they are for)


Im trying to get the compounded interest so that it will work for more
than just annually. I want the user of this program to be able to do
semi annually or monthly even some other defined by the user.

The formula i was given is balance = balance + (balance* (rate/100))


This is my code. Any input is welcome

What help do you need? Do you know the algorithm you need to use? This is
a language newsgroup, not an algorithms newsgroup (and we don't do people's
homework for them). If you need help developing the algorithm for your
problem, you should probably ask your instructor for help, or someone in
your class.

-Howard
 
O

osmium

Drakscon said:
Some one helped out but completely confused me. this is a senario so i
can take it into the actually program im using(variables a, b, c, d are
generic but i have commented about what they are for)


Im trying to get the compounded interest so that it will work for more
than just annually. I want the user of this program to be able to do
semi annually or monthly even some other defined by the user.

The formula i was given is balance = balance + (balance* (rate/100))


This is my code. Any input is welcome


int main()
{
double a,b,c,d;//a is amount to be invested, b is years
invested
//c is compound time, d is interest rate
char ch;//allows user to enter another investment
do{
system("cls");
cout<<"enter an ammount to invest ";
cin>>a;
cout<<"Enter the years to allow to mature ";
cin>>b;
cout<<"How many times a year will it be compounded? ";
cin>>c;
cout<<"What is the rate ";
cin>>d;


for(int i=0;i<b;i++){
for(int h=0;h<c;i++){
a=a+(a*(d/100));
}


}


cout<<"After "<<b<<" years. You have now "<<e<<"
dollars in the
account\n";


cout<<"Would you like to run another? ";
cin>>ch;
}while(ch=='y'||ch=='Y');


return 0;





}

I can't tell what it is you are trying to. Learn C++? Produce a practical
program? (You are much too late for this, programs that do this are already
on the Web.) In any event, perhaps this will be helpful. Note that the
usual way of handling this it to do it for $1. Then, at the very end,
multiply by the number of dollars from the query.

http://en.wikipedia.org/wiki/Compound_interest#Simple_Formulas
 
D

Default User

Drakscon said:
Some one helped out but completely confused me. this is a senario so i
can take it into the actually program im using(variables a, b, c, d
are generic but i have commented about what they are for)


Im trying to get the compounded interest so that it will work for more
than just annually. I want the user of this program to be able to do
semi annually or monthly even some other defined by the user.

The formula i was given is balance = balance + (balance* (rate/100))


This is my code. Any input is welcome

What do you need?
int main()
{
double a,b,c,d;//a is amount to be invested, b is years
invested
//c is compound time, d is interest rate

First of all, pick informative variable names. a,b,c,d? completely
meaningless and maintenance nightmare.
char ch;//allows user to enter another investment
do{
system("cls");
cout<<"enter an ammount to invest ";
cin>>a;
cout<<"Enter the years to allow to mature ";
cin>>b;
cout<<"How many times a year will it be compounded? ";
cin>>c;
cout<<"What is the rate ";
cin>>d;


for(int i=0;i<b;i++){
for(int h=0;h<c;i++){
a=a+(a*(d/100));
}

This formula isn't correct. You have divide the rate by the compounding
frequency, otherwise you'll get far more interest than you should.
You'd get the yearly interest rate every compounding period, which is a
swell deal for the investor, but not so much for the bank.

You have the "brute force" algorithm, which is ok. There's a formula
for direct calculation:

A = P * pow(1+r/m, n);

P = Principal
r = Annual interest rate
m = Number of compounding periods per year
n = Total compounding periods (years * periods per year)
A = Amount Earned After n periods

Either will work, and in fact it's useful as a student to do both and
compare.




Brian
 
D

Drakscon

The program has been written and handed in. What i am trying to do is
for my own gain. This is my 3rd time in C++ but the first two years
were in highschool using Borland Turbo C

and on the variables basis those are not the variables i am using. Im
using Amount, Years, Rate, Time

And being lectured isnt very fun. I politly asked for help so thanks
alot
 
D

Default User

Drakscon said:
The program has been written and handed in. What i am trying to do is
for my own gain. This is my 3rd time in C++ but the first two years
were in highschool using Borland Turbo C

Hope you fixed the algorithm.
and on the variables basis those are not the variables i am using. Im
using Amount, Years, Rate, Time

Why didn't you present it that way? You should always show us the real
code. Remember that for the future questions, if there are any.
And being lectured isnt very fun. I politly asked for help so thanks
alot

It's not at all clear who you are addressing, as you rudely failed to
include quotes as is the standard on usenet. However, a learning
situation is exactly when you should expect to be lectured.

Frankly, your attitude towards people who spent quite a bit of time
(for free) trying to help you is pretty disgusting. You should
apologize to the group.




Brian
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top