I have another assignment I'm working on for class, and I ran into a problem that I can't figure out (big surprise, I know). This program is supposed to calculate the remaining balance of a mortgage after the first, second and third payment. To know we've programmed everything correctly, the instructor has given us the first payment's remaining balance to verify: $5070.31.
The problem is with the formula he gave me. My program is telling me that there is an error with the X in it, that it expected a ; afterwards. I've added, taken away, moved, and did other things with the program to try to troubleshoot the issue, but I can't figure out what I'm doing wrong. I managed to correct some other mistakes as I went along, so that made me happy. Any help is greatly appreciated. Here is the code I wrote up.
#include <iostream>
#include <string>
#include <cmath> //For calculations
#include <iomanip> //For setw() and setprecision()
using namespace std;
const double Payment = 165.25; //Amount of payment per month
const double Monintrate = .09*12; //Monthly Interest Rate
const double Totnum = 36; //Total number of payments
cout << "Your monthly payment is $" << Payment << "." << endl; //States the payment amount
cout << "The annual interest rate is " << Monintrate << endl; //States the interest rate
cout << "The total number of payments is " << Totnum << endl; //States the number of payments
cout << fixed << setprecision(2) << "Your remaining balance after the first payment is $" << balN1 << "." << endl;
cout << "Your remaining balance after the second payment is $" << balN2 << "." << endl;
cout << "Your remaining balance after the third payment is $" << balN3 << "." << endl;
}
That is the formula he gave us. He listed the X as X instead of an asterisk. I know that you have use the asterisk as a multiplication operand.
But, since I hadn't tried it yet, I took your suggestion. It allows the program to run, but it computes incorrectly. All three remaining balances end up being $153.01.
Thank you for your help, but that either showed I have a new problem or wasn't the solution.
There are a LOT of issues with this code, and from what I can see you are having trouble grasping the language and the concept of finance as well.
First let's start by cleaning this up so that you can read things better. This will help you think things through one step at a time which is important with these assignments. Where it says constdouble balN1 = put a zero then a semicolon to the right of it and comment or delete the rest of that crap out. Repeat this step for 'balN2' and 'balN3'.
Your 'Payment' variable is a variable that doesn't change with the way you have it declared so you don't need to assign it like it were a data type. IOW there is no need for 'X'.
Your Monthly Interest Rate is being calculated wrong. You are doing something strange by multiplying the monthly rate, ".09", by 12, the number of months in a year. Fix that.
To calculate the balance of a mortgage after the monthly payment is made the formula is:
Balance = (Balance * (1 + interest_rate)) - payment;
If you declare your variables right you can even use that line in your code.
Have you coverd loops yet? I don't mean just in class, often times class lecture is a week or so behind what you are supposed to be read up on. Weither you've covered loops or not has an impact on how we go about the rest of this code.
EDIT: I started writing my post before anything else was up here and I got distracted so sorry that I go off on my own way of solving things. M4ster r0shi is mistaken however, you do not divide a MONTHLY interest rate by 12, you only do this when you are given an ANNUAL interest rate and are expected to calculate the monthly rate on your own.
Thank you for your input. I'm not grasping programming at all. I know this is not the correct field for me to go into which is why I'm persuing a different major in the spring. I took the previous suggestions and made the changes, and the program works correctly now. My instructor provides no feedback on what I should and should not put into my code. He merely checks what I have done and signs off a grade. So far, all of my programs have received full credit.
Also, we will not be covering looping for a few more weeks. It seemed odd that we would have a program like this before we covered looping, but here we are.
you do not divide a MONTHLY interest rate by 12, you only do this when you are given an ANNUAL interest rate and are expected to calculate the monthly rate on your own
Maybe I'm missing something here, but I think that's exactly what he does.
The annual interest rate is 0.9 and he divides it by 12 to find the monthly interest rate.
@Kness:
Though, the cout statement should be:
cout << "The monthly interest rate is " << Monintrate << endl; //States the interest rate
I suppose that I got confused with the labeling and the absence of the assignment being posted. If the OP was given an annual interest rate then I appoligies, you are correct.
Most likely, you are correct. All C++ has managed to do since day 1 is frustrate me. I really appraciate everyone's help. You will probably be hearing from me a lot.