8 Replies - 833 Views - Last Post: 08 October 2009 - 12:40 PM Rate Topic: -----

#1 qtek16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 05-October 09

Interest Rate Problem

Post icon  Posted 05 October 2009 - 09:55 AM

Ok so I am doing an interest rate problem.

essentially I have to use this formula (supposedly)
Accumulative Value = investmentAmount * (1 + MonthlyInterestRate) NumberofYears*12 I think that is supposed to be a power--

to yield a table that looks like this

Years Future value
1 1093.8
2 1196.41
3 ..

30 14730.57


The issue I am having is with the formula. I do not think it is right.

I can get the right values for year 1 but thats it.

any suggestions?

# include <iostream>
# include <cmath>
# include <string>
# include <iomanip>
using namespace std;

int main ()

{
//declaring the variables

double initial = 0;
int years;
double annualinterest = 0;
double monthlyinterest = 0;
double future = 0;

cout.setf(ios::fixed); 
cout.setf(ios::showpoint); 
cout.precision (2);  

// executable section
	
cout << "Please enter an investment principal " << endl;
cin >> initial;

cout << "Please enter the interest rate " << endl;
cin >> annualinterest;

cout << "Year" << setw (27) << "Future Value" <<endl;

	for (years = 1; years <=30; years++)
	{
	monthlyinterest = (annualinterest /100) / 12;
	future = pow((monthlyinterest + 1),12) * (years) * (initial);

	
	cout << years << setw (27) << future << endl;
	
	}
	
	
return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Interest Rate Problem

#2 lowlyGiant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 05-October 09

Re: Interest Rate Problem

Posted 05 October 2009 - 10:29 AM

Your loop looks right, though you aren't compounding the interest. To do that ( compound the interest ), you should declare another double before the loop, say currInt. Then, the first line in your loop should set currInt to initial:

currInt = initial;

Next, you should multiply the currInt by the monthly interest ( NOT monthly interest + 1 ):
currInt *= monthlyInterest;

Finally, add the current interest to the initial, which is now the running ( the identifier "initial" is still fine, the user would never know ):

initial += currInt;

Happy hacking!
;)
Was This Post Helpful? 0
  • +
  • -

#3 qtek16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 05-October 09

Re: Interest Rate Problem

Posted 05 October 2009 - 12:28 PM

View PostlowlyGiant, on 5 Oct, 2009 - 09:29 AM, said:

Your loop looks right, though you aren't compounding the interest. To do that ( compound the interest ), you should declare another double before the loop, say currInt. Then, the first line in your loop should set currInt to initial:

currInt = initial;

Next, you should multiply the currInt by the monthly interest ( NOT monthly interest + 1 ):
currInt *= monthlyInterest;

Finally, add the current interest to the initial, which is now the running ( the identifier "initial" is still fine, the user would never know ):

initial += currInt;

Happy hacking!
;)



Hmm should I forget about the POW function all together?
Was This Post Helpful? 0
  • +
  • -

#4 qtek16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 05-October 09

Re: Interest Rate Problem

Posted 08 October 2009 - 06:43 AM

View Postqtek16, on 5 Oct, 2009 - 11:28 AM, said:

View PostlowlyGiant, on 5 Oct, 2009 - 09:29 AM, said:

Your loop looks right, though you aren't compounding the interest. To do that ( compound the interest ), you should declare another double before the loop, say currInt. Then, the first line in your loop should set currInt to initial:

currInt = initial;

Next, you should multiply the currInt by the monthly interest ( NOT monthly interest + 1 ):
currInt *= monthlyInterest;

Finally, add the current interest to the initial, which is now the running ( the identifier "initial" is still fine, the user would never know ):

initial += currInt;

Happy hacking!
;)



Hmm should I forget about the POW function all together?



Ok so I am trying to pass values.

see my code--It runs but I cant get the loop to display the actual calculations.

# include <iostream>
# include <cmath>
# include <string>
# include <iomanip>
using namespace std;




int main ()
{

//declaring the variables


int years;
double annualinterest = 0;
double initial = 0;

cout.setf(ios::fixed); 
cout.setf(ios::showpoint); 
cout.precision (2);  

// executable section

cout << "Please enter an investment principal " << endl;
cin >> initial;

cout << "Please enter the interest rate " << endl;
cin >> annualinterest;
cout << "Year" << setw (30) << "Future Value" <<endl;

void calculation ();

return 0;
}



void calculation (int& years, double& annualinterest, double& initial)
{
double monthlyinterest = 0;
double future = 0;

for (years = 1; years <=30; years++)
	{
	
	monthlyinterest = (annualinterest /100) / 12;
	future = pow((monthlyinterest + 1),(years *12)) * (initial);

	cout << years << setw (28) << " " << future << endl;
	
	}


}	


Was This Post Helpful? 0
  • +
  • -

#5 AntonWebsters  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 88
  • View blog
  • Posts: 428
  • Joined: 15-August 09

Re: Interest Rate Problem

Posted 08 October 2009 - 07:25 AM

From the main class in your code, the way you called the calculation() function is wrong..there shouldn't be a "void" in front, and you need to pass three parameters to the function. Is that what that's causing the problems?
Was This Post Helpful? 0
  • +
  • -

#6 qtek16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 05-October 09

Re: Interest Rate Problem

Posted 08 October 2009 - 07:46 AM

View PostAntonWebsters, on 8 Oct, 2009 - 06:25 AM, said:

From the main class in your code, the way you called the calculation() function is wrong..there shouldn't be a "void" in front, and you need to pass three parameters to the function. Is that what that's causing the problems?



I am not sure, I can get it to run but it will just display

Year Future Value


After I input the initial and the amount.

Almost like it is not doing any of the calculations or at least returning them
Was This Post Helpful? 0
  • +
  • -

#7 qtek16  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 05-October 09

Re: Interest Rate Problem

Posted 08 October 2009 - 08:56 AM

View Postqtek16, on 8 Oct, 2009 - 06:46 AM, said:

View PostAntonWebsters, on 8 Oct, 2009 - 06:25 AM, said:

From the main class in your code, the way you called the calculation() function is wrong..there shouldn't be a "void" in front, and you need to pass three parameters to the function. Is that what that's causing the problems?



I am not sure, I can get it to run but it will just display

Year Future Value


After I input the initial and the amount.

Almost like it is not doing any of the calculations or at least returning them



any other suggestions?
Was This Post Helpful? 0
  • +
  • -

#8 AntonWebsters  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 88
  • View blog
  • Posts: 428
  • Joined: 15-August 09

Re: Interest Rate Problem

Posted 08 October 2009 - 10:03 AM

I think you need to add a cin >> years; to prompt the user to enter the years, and then change void calculation(); to calculation(years,annualinterest,initial); so that the function takes in the three parameters needed.

This post has been edited by AntonWebsters: 08 October 2009 - 10:04 AM

Was This Post Helpful? 0
  • +
  • -

#9 jjl  Icon User is online

  • Engineer
  • member icon

Reputation: 869
  • View blog
  • Posts: 3,995
  • Joined: 09-June 09

Re: Interest Rate Problem

Posted 08 October 2009 - 12:40 PM

your not calling your function

in your main you put
//WHY ARE YOU REDECLARING YOUR FUNCTION
void calculations(//WHERE ARE THE PARAMETERS!!);


call like this
calculations(years, annualIntrest, years);



EDIT:: You also have no prototype

This post has been edited by ImaSexy: 08 October 2009 - 12:40 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1