| | |
Mortgage Calculator problems
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hello everyone....
I have gotten this far with my mortgage calculator....the problem is the while loop and the actual calculation isn't working correctly. The while loop really doesnt do what i was hoping for it to do...and being pretty amature at this...i am not sure where to go. i built this program in the first week of class with hard coded varibles in the code, and it worked just fine....now that the user needs to enter the code...it doesnt do so well....and help would be great. Thank you to everyone!!
I have gotten this far with my mortgage calculator....the problem is the while loop and the actual calculation isn't working correctly. The while loop really doesnt do what i was hoping for it to do...and being pretty amature at this...i am not sure where to go. i built this program in the first week of class with hard coded varibles in the code, and it worked just fine....now that the user needs to enter the code...it doesnt do so well....and help would be great. Thank you to everyone!!
c++ Syntax (Toggle Plain Text)
/* Write the program as a procedural C++ program. Calculate and display the mortgage payment amount using the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage as input by the user. Allow the user to loop back and enter new data or quit. Insert comments in the program to document the program. */ #include <iostream> #include <cmath> using namespace std; int main () { double principle = 0; double interest = 5.7; int term = 30 * 12; double total; double monthlyInterest = interest * 12; bool validNum = false; cout << "Please enter principle amount: "; cin >> principle; cout << "You entered: " << principle << endl << endl; while (validNum == false) { cout << "Please enter a positive number: "; cin >> principle; cout << "You entered: " << principle << endl << endl; if (principle <= 0) { cout << "You did not input a correct number" << endl; cout << "Please re-enter the number!" << endl << endl; } else validNum = true; } cout << "Enter desired Interest Rate: " << endl; cin >> interest; while (validNum == false) { cout << "Please enter a positive number: "; cin >> interest; cout << "You entered: " << interest << endl << endl; if (interest <= 0) { cout << "You did not input a correct number" << endl; cout << "Please re-enter the number!" << endl << endl; } else validNum = true; } //cout << "Thank you for entering a valid number!" << endl; total = (principle * monthlyInterest)/(1-pow(1 + monthlyInterest, -term)); cout << "Your priniple is " << principle << endl; cout << "Your Interste rate is: " << interest << endl; cout << "Term Length: " << term << " Months" << endl; cout << "Your total monthly payment is: " << total << endl; return 0; }
In order to allow the user to enter new data or quit, you will want to place all of your code after your variable declarations in a while loop. That way, the user can go through the program as many times as he or she wants:
Hope that helps!
-D
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cmath> #include <string> using namespace std; int main () { double principle = 0; double interest = 5.7; int term = 30 * 12; double total; double monthlyInterest = interest * 12; bool validNum = false; //create a yesNo variable to allow the user to select //if her or she wants to keep using the program string yesNo = "y" while(yesNo == "y") { //contents of the program, then add question at the //end asking user if they would like to use it again }
Hope that helps!
-D
•
•
•
•
Okay, I understand the the yes no part. But when i run the current loop i have it doesnt seem to work right. What is it i am doing wrong with it? I have tried so many different things, but i just cant seem to get it to work.
-D
•
•
Join Date: Oct 2008
Posts: 45
Reputation:
Solved Threads: 11
You haven't said anything about the desired output of your program, the total you were expecting, what testsdid you do , if you ae using compound interest, then the formula looks wrong to me.
Whether the interest rates are given directly or you are supposed to divide by 100 and then store those values, whether the compounding is done monthly or annually is still not clear going by
Did you read your own thread
http://www.daniweb.com/forums/thread210871.html
Whether the interest rates are given directly or you are supposed to divide by 100 and then store those values, whether the compounding is done monthly or annually is still not clear going by
C++ Syntax (Toggle Plain Text)
int term = 30 * 12; //30 years right? double monthlyInterest = interest * 12; //what exactly for and //it should be annualInterest
Did you read your own thread
http://www.daniweb.com/forums/thread210871.html
Last edited by zalezog; Aug 14th, 2009 at 12:43 pm.
Hey everyone. Thank you for the help so far i really am very grateful for all of it. I think i have the main part of the program working. The part I am having a problem with is the calculation for the total loan. I need to calculate the total per month of the loan. When i do the calculation at the end it gives me a number like 1.368e+07 and i am not sure how to correct this. Can someone help me on this thanks.
c++ Syntax (Toggle Plain Text)
#include <math.h> #include <iostream> using namespace std; int main () { double principle = 0; double interest = 5.7; int term = 30 * 12; double total; //double interest = i * 100; double monthlyInterest = interest * 12; int choice; do { cout << "Please enter total loan amount" << endl; cin >> principle; cout << "Your entered: " << principle << endl; cout << "Please enter interest rate " << endl; cin >> interest; cout << "Your entered: " << interest << endl; cout << "Please enter the term in years: " << endl; cin >> term; cout << "Your entered: " << term << endl; total = (principle * monthlyInterest)/(1-pow(1 + monthlyInterest, -term)); //total for mortgage cout << "Your total monthly payment is: " << total << endl; cout << "Would you liek to play again?" << endl; cout << "1 for yes" << endl; //gives user choice cout << "2 for no" << endl; //gives user choice cin >> choice; }while (choice==1); return 0; }
If you want fixed point then user
This will output number such as 1.2000000000 instead of
1.2e10
C++ Syntax (Toggle Plain Text)
cout.setf(std::ios_base::fixed,std::ios_base::floatfield);
This will output number such as 1.2000000000 instead of
1.2e10
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle. 2) Problem 2[b]solved by : jonsca
Give me an input values and what the output value supposed to be.
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle. 2) Problem 2[b]solved by : jonsca
![]() |
Similar Threads
- mortgage calculator (C++)
- Need Help with Java Mortgage Calculator (Java)
- Sequential file problems (VB.NET)
- Problems with reading from a sequential file (C++)
- roman numeral calculator problems (C++)
- Help with Mortgage Calculator (C++)
- Mortgage Calculator (C++)
- Writing Applet ActionListener Mortgage Calculator (Java)
Other Threads in the C++ Forum
- Previous Thread: Converting uppercase words to lowercase
- Next Thread: Starting out with C++
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






