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!!
/*
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;
}