Compound interest rate problem

the calculations are not right - any help would really be appreciated

Page 1 of 1

4 Replies - 3645 Views - Last Post: 06 October 2009 - 12:36 PM Rate Topic: -----

#1 baross  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 21-May 09

Compound interest rate problem

Post icon  Posted 05 October 2009 - 09:30 PM

[quote]
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <conio.h>

using namespace std;


char display_Menu(char Choice)
{   cout << endl; 
	cout << "This program demonstrates the benefits of compounding interest." 
	<< endl;
	cout << endl;
	cout << "Compare Annual Compounding to:" << endl;
	cout << "	M - Monthly Compounding" << endl;
	cout << "	W - Weekly Compounding" << endl;
	cout << "	D - Daily Compounding" << endl;
	cout << "	E - Exit Program" << endl;
	cout << endl;
	cout << endl;
	cout << "Enter choice from Menu above: ";
	cin >> Choice;
	cout << endl;
	Choice = toupper(Choice);
	if ((Choice != 'M') && (Choice != 'W') &&
	(Choice != 'D') && (Choice != 'E'))
	{
		 cout << "Please enter a choice from above" << endl;
		 cin >> Choice;
	}
	if (Choice == 'E')
	{
		 exit(0);
	} 
	return (Choice);
}

double money(double Beginning_Balance)
{
	cout << "Enter your beginning balance: ";
	cin >> Beginning_Balance;
	if (Beginning_Balance < 0)
	{
		 cout << "Please enter positive value" << endl;
		 cin >> Beginning_Balance;
	}  
	return (Beginning_Balance);   
}


double Interest(double& Interest_Rate)
{
	cout << "Enter an annual interest rate: ";
	cin >> Interest_Rate;
	Interest_Rate = Interest_Rate /100;
	
	if (Interest_Rate >.50)
	{
		 cout << "Please enter interest rate lower than 50%" << endl;
		 cin >> Interest_Rate;
		 
	}
	Interest_Rate = Interest_Rate * 100;
	return (Interest_Rate);
}

int Years(int Term_Years)
{
	cout << "Enter a term in whole years: ";
	cin >> Term_Years;
	if (Term_Years > 100)
	{
		 cout << "Enter term less than 100 years" << endl;
		 cin >> Term_Years;
	}
	return (Term_Years);
}


double funcCalculation(char& compounding_choice, double& Start_Balance, 
double& interest_rate, int& term_years, double Calc)

{
	double principal, result, CalcTotal;
	int cDay, cWeek, cMonth, cYear;
	const double MONTH=12;
	const double Week=52;
	const double YEAR=365;
	principal = Start_Balance;

	Calc = 0;
	switch (compounding_choice)
	{
		 case 'M':
		   interest_rate = interest_rate + 1;
		   for (cYear = 0; cYear < term_years; cYear++)
		   {
			 for (cMonth = 0; cMonth < 12; cMonth++)
			 {
				result = principal * (interest_rate/cMonth);
			 }
			 CalcTotal = result;
		   }
		   Calc =  principal-CalcTotal;
		   break;
		 case 'W':
		   interest_rate = interest_rate + 1;
		   for (cYear = 0; cYear < term_years; cYear++)
		   {
			 for (cWeek = 0; cWeek < 52; cWeek++)
			 {
				result = principal * (interest_rate/cWeek);
			 }
			 CalcTotal = result;
		   }
		   break;
		 case 'D':
		   interest_rate = interest_rate + 1;
		   for (cYear = 0; cYear < term_years; cYear++)
		   {
			 for (cDay =0; cDay < 365; cDay++)
			 {
				result = principal * (interest_rate/cYear);
			 }
			 CalcTotal = result;
		   }
		   break;
	}
	Calc = CalcTotal;
	interest_rate = interest_rate -1;
	return (Calc);
}



int main()
{
	char Choice;
	char Compounding, again;
	double Start_Balance, rate, Calculation, Final_Calc,Calculate;
	int Term_Years;
	
   do
   {
  
	char compounding_choice = display_Menu(Compounding);
	double Start_Balance = money(Start_Balance);
	double interest_rate = Interest(rate);
	int term_years = Years(Term_Years);
	double Calculation = funcCalculation(compounding_choice, Start_Balance, 
	interest_rate, term_years, Calculate);
	Final_Calc = Start_Balance + Calculation;
   
	cout << fixed << showpoint << setprecision(2) << endl; 
	cout << "------------------------------------------------" << endl;
	cout << "					 Results					" << endl;
	cout << "------------------------------------------------" << endl;
	cout << endl;
	cout << "Beginning Balance: " << Start_Balance << endl;
	cout << "Return after 5 years at " << interest_rate 
	<< "% interest annually:" << endl;
	cout << endl;
	cout << "					 Return	   Ending Balance" << endl;
	cout << "Compounded Yearly:   $" << setw(4) << Calculation << setw(4) << "$" << setw(10) 
	<< Final_Calc << endl;
	cout << "Compounded Weekly:   $" << setw(4) << Calculation << setw(4) << "$" << setw(10)
	<< Final_Calc << endl;
	cout << "------------------------------------------------" << endl;
	
	
   Choice = toupper(Choice);
   } while (Choice != 'E');
   return 0; 

  cout<<endl<<endl;
  cout << "Press [enter] to exit" <<endl;
  cin.ignore(); //needed because of keyboard input
  cin.get();
  return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Compound interest rate problem

#2 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1112
  • View blog
  • Posts: 4,619
  • Joined: 09-June 09

Re: Compound interest rate problem

Posted 05 October 2009 - 10:18 PM

Do you really expect us to sit here for hours reading your code, pinpoint the problem the post it
Was This Post Helpful? 0
  • +
  • -

#3 baross  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 21-May 09

Re: Compound interest rate problem

Posted 05 October 2009 - 11:12 PM

View PostImaSexy, on 5 Oct, 2009 - 09:18 PM, said:

Do you really expect us to sit here for hours reading your code, pinpoint the problem the post it

Quote

The calculation is not calculating correctly! What part of that are you not getting!

Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5940
  • View blog
  • Posts: 12,865
  • Joined: 16-October 07

Re: Compound interest rate problem

Posted 06 October 2009 - 05:35 AM

First figure out the number of payments, then just use one loop.

int getNumberOfPayments(char compounding_choice, int term_years) {
	if (compounding_choice=='M') { return term_years * 12; }
	if (compounding_choice=='W') { return term_years * 52; }
	// daily
	return term_years * 365;
}



Also, for this, doubles can do strange things. Work in ints and pennies for better results.
Was This Post Helpful? 0
  • +
  • -

#5 baross  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 21-May 09

Re: Compound interest rate problem

Posted 06 October 2009 - 12:36 PM

Quote

View Postbaavgai, on 6 Oct, 2009 - 04:35 AM, said:

First figure out the number of payments, then just use one loop.

int getNumberOfPayments(char compounding_choice, int term_years) {
	if (compounding_choice=='M') { return term_years * 12; }
	if (compounding_choice=='W') { return term_years * 52; }
	// daily
	return term_years * 365;
}



Also, for this, doubles can do strange things. Work in ints and pennies for better results.

quote]Thank you
[
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1