Hello bethmayweather,
My apologies I thought I had said something about using code tags, but must have been thinking about something else.
PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.
Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
|
Working with what you started with I did rearrange and make some changes to your variable definitions.
1 2 3 4 5 6 7 8 9 10
|
constexpr double YEARS{ 30.0 };
double principal{ 100000.0 };
double annualInterestRate{ 4.5 };
double mPayment{};
double monthlyInterestRate = 0.0;
double ratio = 0.0;
double paymentSchedule = 0.0;
//double loanAmount = 0.0; // <--- Same as "principal" Not needed.
double totalCost = 0.0, totalLoanPayment{}, totalInterestPayment{};
|
The first line I made a constant because this should not be changed. At least for now. Maybe in the future you may need to change this.
Lines 2 and 3 are designed to bypass the input so that you can get right to checking the rest of the program with out having to type the same thing every time the program runs. To go along with you can do the input this way:
1 2 3
|
//std::cout << "\n Enter in principal: ";
//std::cin >> principal;
std::cout << "\n Enter in principal: " << principal << '\n';
|
When you finished testing and debugging uncomment lines 1 and 2 and comment line 3. Then if you ever need it it is there for you.
You have these lines in your last code:
1 2 3 4 5
|
int monthlyInterestRate = annualInterestRate / 12.0;
double ratio = ((totalCost - loanAmount) / (loanAmount)) * 100;
double totalLoanPayment = mPayment * 12 * years;
double totalInterestPayment = totalLoanPayment - principal;
|
Lines 1 and 2 are already defined and just need to be used not redefined.
Lines 4 and 5 are OK if you define the variable hers, but since all your other variables are at the top of main I would put the definition there. That is the bold type in the above code.
You defined a variable "totalCost" but never give it a value. This would be done after you give "monthlyInterestRate" its value because you will need it to figure "totalCost". I ended up at this web sight to get the formula for this
https://www.1728.org/loanfrm4.htm That was a lot of fun (not) it took me over an hour to find the mistake I made when entering the formula.
In the end with everything that you input or calculate I came up with this:
Enter in principal: 100000.00
Enter in annual interest rate: 4.50
LOAN SUMMARY
---------------------------------
Loan amount $ 100000.00
Interest rate 4.50%
Total Interest $ 82406.71
Monthly payment $ 506.69
Total cost $ 182406.71
Ratio paid over principal 82.41%
Press Enter to display the payment schedule
|
I admit that I put a little time into setting up the output here so that the decimal points all line up. If you are interested I will help you set up the output this way.
When you get all your variables to match these numbers and can display them on the screen then you will be ready for the for loop to display the schedule.
Hope that helps,
Andy