Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 10-07-2004, 01:33 PM   #1 (permalink)
B00tleg
Registered User
 
B00tleg's Avatar
 
Join Date: Oct 2004
Posts: 9
B00tleg is on a distinguished road
Help on interest program

I'm writing code for an interest program that will take the principal amount of the account, show the interest, show how many times it was compounded, and show the total amound in the account after all the interest is added up and also show a seperate amount for the interest accrued. This program assumes no other deposits are made into the account and the length of time of interest is 12 months.

This is the code I've come up with so far. I'm trying to break the equation amount = principal * (1 + rate / T) ^T into steps to get the total amount in the account and interest accrued. Any help on this would be appreciated as I believe this assignment is driving me slowly schizophrenic. Hopefully I've provided enough info but I'll be more then glad to fill in any missing parts. Thanks in advance.

Regards,
Matt Stacey

Code:
// CSDT 117 chp3chall12.cc
// by Matt Stacey
// 10/05/2004
// Purpose: This program will ask for an interest rate, number of 
// times the interest is compounded and display a report.


#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
	float interestRate;
	float timesCompounded;
	float principal;
	float totalInterest;
	float totalInSavings;
	float compoundInterest;

	cout << "Enter the principal amount in the account: " <<endl;
	cin >> principal;
	cout << "Enter the interest rate as a floating poing decimal: " <<endl;
	cin >> interestRate;
	cout << "Enter the number of times the interest was compounded: "         <<endl;
	cin >> timesCompounded;
	cout << "Interest Rate: " <<interestRate << "%" <<endl;
	cout << "Times Compounded: " <<timesCompounded <<endl;;
	cout << "Principal: " << principal <<endl;

	cout << setiosflags(ios::fixed) << setprecision(2);

	totalInterest = interestRate / timesCompounded;
	totalInterest = 1 + interestRate;
	totalInterest = pow(interestRate, timesCompounded);
	totalInSavings = principal * totalInterest;
 
	cout << "The total interest accrued is $" <<totalInterest<<endl;
	cout << "The total amount in savings is $" 
		  << totalInSavings <<endl;

	return 0;
}
B00tleg is offline   Reply With Quote
Old 10-07-2004, 02:28 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
Next time use the "CODE" tags .

Does this come closer to what you want?
Code:
// Purpose: This program will ask for an interest rate, number of
// times the interest is compounded and display a report.

//amount = principal * (1 + rate / T) ^T

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
  double interestRate, timesCompounded, principal, totalInterest, totalInSavings,
      compoundInterest;

  cout << "Enter the principal amount in the account: " <<endl;
  cin >> principal;
  cout << "Enter the interest rate as a floating poing decimal: " <<endl;
  cin >> interestRate;
  cout << "Enter the number of times the interest was compounded: "         <<endl;
  cin >> timesCompounded;
  cout << "Interest Rate: " <<100*interestRate << "%" <<endl;
  cout << "Times Compounded: " <<timesCompounded <<endl;;
  cout << "Principal: " << principal <<endl<<endl;;

  cout << setiosflags(ios::fixed) << setprecision(2);

   totalInterest = 1 + (interestRate / timesCompounded);
  compoundInterest = pow(totalInterest, timesCompounded);
  totalInSavings = principal * compoundInterest;

  cout << "The total interest accrued is $" <<totalInterest<<endl;
  cout << "The compound interest is $" <<compoundInterest<<endl;
  cout << "The total amount in savings is $"<< totalInSavings <<endl;
  //Optional line below:
  system("PAUSE");

  return 0;
}
By the way, standard C++ proposes "double" as the standard precision. Forget float.
__________________
Valmont is offline   Reply With Quote
Old 10-07-2004, 08:50 PM   #3 (permalink)
B00tleg
Registered User
 
B00tleg's Avatar
 
Join Date: Oct 2004
Posts: 9
B00tleg is on a distinguished road
Hi just wanted to say thanks for the response to my thread. Just wanted to post the resultant code for this program that got it working so anyone else doing something similar can compare notes if they want. Here it is, thanks again. This looks like a really good community to get involved with.

Regards, Matt Stacey

Code:
// CSDT 117 chp3chall12.cc
// by Matt Stacey
// 10/05/2004
// Purpose: This program will ask for an interest rate, number of 
// times the interest is compounded and display a report.


#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
	double interestRate;
	double timesCompounded;
	double principal;
	double totalInterest;
	double totalInSavings;
	double compoundInterest;

	cout << "Enter the principal amount in the account: " <<endl;
	cin >> principal;
	cout << "Enter the interest rate as a floating poing decimal: " <<endl;
	cin >> interestRate;
	cout << "Enter the number of times the interest was compounded: "         <<endl;
	cin >> timesCompounded;
	cout << "Interest Rate: " <<interestRate << "%" <<endl;
	cout << "Times Compounded: " <<timesCompounded <<endl;;
	cout << "Principal: " << principal <<endl;

	cout << setiosflags(ios::fixed) << setprecision(2);

	totalInSavings = principal * pow(1+((interestRate/100.0) / 	timesCompounded),timesCompounded);
	totalInterest = totalInSavings - principal;
  
 
	cout << "The total interest accrued is $" <<totalInterest<<endl;
	cout << "The total amount in savings is $" 
		  << totalInSavings <<endl;

	return 0;
}
B00tleg is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Deadlock Detection Program Help... coolsc81 Standard C, C++ 2 10-26-2004 06:14 AM
Help on starting new program B00tleg Standard C, C++ 21 10-17-2004 12:58 PM
Need help on program B00tleg Standard C, C++ 1 10-12-2004 12:02 AM


All times are GMT -8. The time now is 08:55 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting