473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Loan Calculator Formula Help, C++ Code

2
Hello I am very new to programming as you will probably tell by my code, if anyone can help me solve my issue it would be much appreciated. I need to get this formula:
http://imageshack.com/a/img809/8927/gq05.png

into c++ code with the variables below and I'm having quite a hard time, as I said, any help is appreciated.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     double loanAmount = 25000;
  10.     double interestRate = 7;
  11.     double payment = 495.03;
  12.     double paymentsMade = 12;
  13.     double loanbalance = pow((loanAmount(1 + interestRate / 12 * 100), paymentsMade)) - (payment / interestRate / 12 * 100)* pow(loanAmount((1 + interestRate / 12 * 100, paymentsMade) - 1));
Feb 8 '14 #1
1 3032
weaknessforcats
9,208 Expert Mod 8TB
This code:
Expand|Select|Wrap|Line Numbers
  1. double loanbalance = pow((loanAmount(1 + interestRate / 12 * 100), paymentsMade)) - (payment / interestRate / 12 * 100)* pow(loanAmount((1 + interestRate / 12 * 100, paymentsMade) - 1)); 
is too complicated for me to understand either.

Use smaller steps. Calculate for a payment how much is interest and how much is principal. Do this for one payment Then the loan balance is the current balance minus the part of the payment that was principal.

You could put those statements in a loop and amortize the loan.

Readability is a big issue in C++. Choose several simple statements over one big one. Beginners especially should not use the comma operator.

Break this complex statement into two or three smaller ones.

Expand|Select|Wrap|Line Numbers
  1. double interest;
  2. double CurrentBalance;
  3.  
  4. CurrentBalance = loanAmount;
  5.  
  6. interest = CurrentBalance * interestRate;  //for a year
  7.  
  8. CurrentBalance = CurrentBalance - (payment - interest/12);
Feb 8 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: alex | last post by:
I need a more advanced formula than just an average for calculating items rating. I have: raitng value is on scale 1 to 10. s - sum of all ratings for an item n - number of rates (votes)
8
by: Agusta06 | last post by:
Greetings, I am working on writing a C++ program and am relatively new in doing so. I am finding computer programming interesting and enjoy learning how to write the source code. If anyone...
1
by: phjones | last post by:
please help resolve some error messages code is compling with errors see below the code. I am new at this please help! /** * @(#)3 Mortgage loans.java * * 3 Mortgage loans application * ...
0
by: journeycross | last post by:
Hi, I'm trying to enter a formula to display a fixed value for each named category. I'm getting error messages when I try various configurations of this statement. Any idea why it is invalid? ...
12
Presto731
by: Presto731 | last post by:
I'm having a formulating dilemma that I hope anyone can help with. I need to do some reporting for a list of people so I can know there anniversary dates for charging them. However the way it works...
2
by: deezle | last post by:
Hello, I am trying to get my calculator GUI to +,-,* and /. I have got all of them to work except my division. I was wondering if someone could helpme figure out the problem. Any input would help...
6
by: NoviceJava | last post by:
I'm new to JAVA and need some help writing a simple calculator program. Here are the instructions: -expects espression with 2 operands together with either +, -, *, or / operator -espects only...
4
by: NigelBrown | last post by:
Hi All, This is prob easy but I have the below formula that is not working, how do I include an And statement within the IsNull to look at 2 combo boxes ? I have tried to do it a couple of ways...
3
by: nuken | last post by:
I need someone to look over these because I'm not sure how to make it write the correct output. I know its kind of a lot of code to look at but any help would be much apprecitated. I think the...
1
by: Mohammad Ahmed | last post by:
Hi, I need hep with getting a formula for some customer data we have for Microsoft Access. We need to work what the expected contract end date will be for our customers. For example: Mr...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.