### Morgage code will not work!

Soo, I am not good at this. I keep starting over and now its a mess. I do not understand why when I ask for the principal amount it allows two responses. And then it doesn't ask the credit score..then I can not figure out how to make the numbers work within a perimeter. loan amount only between \$0-800,000. I got it to not allow letters in int. but can't get the rest.
(can not be a crazy amount or neg #)
2. Ask the credit score which I have a table excellent-720-850(rate=2.75%-4.0%)
3. The interest rate has to be calculated with a rand # withing the range. using Enum
4.then calculate payments for 12 months.

that's it!! but I can not seem to figure out the beginning.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667`` `````` // Week 1 #include #include #include using namespace std; int main() { double principle = 0; char again = 'y'; int creditScore; int loanLength; bool P = false; while (again == 'y' ) { //Get the amount of principal wanted cout << "Type in the principal amount:\n"; while (!(cin >> principle)) { while (!(principle)); { if (principle <= 100000 && principle > 0) { P = true; } else { cout << "Pick a number between 0 - 100000:\n"; cin >> principle; } } cout << "Must be a number:\n"; cin.clear(); cin.ignore(100, '\n'); } if (principle == 0) //Assign credit score cout << "What is your credit score?:\n"; while (!(cin >> creditScore)) { cout << "Must be a number:\n"; cin.clear(); cin.ignore(100, '\n'); } cout << "What length of a loan do you want?:10,15 or 30\n"; while (!(cin >> loanLength)) { cout << "Must be a number 10,15 or 30:\n"; cin.clear(); cin.ignore(100,'\n'); } { cout << "Congratulations! You are on the path to getting a great loan!\n"; } } return 0; }``````
Here's your code with clearer indentation.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556`` ``````#include #include #include using namespace std; int main() { double principle = 0; char again = 'y'; int creditScore; int loanLength; bool P = false; while (again == 'y') { //Get the amount of principal wanted cout << "Type in the principal amount:\n"; while (!(cin >> principle)) { while (!(principle)); { if (principle <= 100000 && principle > 0) { P = true; } else { cout << "Pick a number between 0 - 100000:\n"; cin >> principle; } } cout << "Must be a number:\n"; cin.clear(); cin.ignore(100, '\n'); } if (principle == 0) //Assign credit score cout << "What is your credit score?:\n"; while (!(cin >> creditScore)) { cout << "Must be a number:\n"; cin.clear(); cin.ignore(100, '\n'); } cout << "What length of a loan do you want?:10,15 or 30\n"; while (!(cin >> loanLength)) { cout << "Must be a number 10,15 or 30:\n"; cin.clear(); cin.ignore(100, '\n'); } { cout << "Congratulations! You are on the path to getting a great loan!\n"; } } return 0; }``````

1. The while loop at line 19 will either do nothing at all, or do nothing forever.
That ; at the end is a killer.

2. You don't prompt for credit score because of the if on line 33. This can never be true because of line 21.
Thanks!
How do you control the number of answers that can be given back?
How can I isolate the 10, 15 and 30?
Like
if ( loanLength == 10 || loanLength == 15 || loanLength == 30 )
How, do I only prompt one question and not allow two entries for my questions?
I do not understand your question, but this

 ``12345678`` ``````{ if (principle <= 100000 && principle > 0) { P = true; } else { cout << "Pick a number between 0 - 100000:\n"; cin >> principle; } }``````

seems wrong. I think you meant this:
 ``12345`` ``````do { cout << "Pick a number between 0 - 100000:\n"; cin >> principle; } while (principle > 100000 || principle < 0)``````

your code sets P but checks principle, and it only checks if its zero or not. You can fix yours by putting P into the while loop, but its cleaner with the do-while approach and no P at all.
Last edited on
Make one loop work first, then add a second and third loop when you understand what's going on.

 ``123456789101112131415161718`` ``````#include #include using namespace std; int main() { double principal = 0; cout << "Type in the principal amount (<100000):\n"; // While there is input failure, or it's out of range while( !(cin >> principal) || principal < 0 || principal > 100000 ) { cout << "Pick a number between 0 - 100000:\n"; cin.clear(); cin.ignore(100, '\n'); } cout << "principal=" << principal << endl; }``````

Becomes
 ``12345678910111213141516171819202122232425262728`` ``````#include #include using namespace std; int main() { double principal = 0; int creditScore; cout << "Type in the principal amount (<100000):\n"; // While there is input failure, or it's out of range while( !(cin >> principal) || principal < 0 || principal > 100000 ) { cout << "Pick a number between 0 - 100000:\n"; cin.clear(); cin.ignore(100, '\n'); } cout << "principal=" << principal << endl; cout << "What is your credit score?:\n"; while( !(cin >> creditScore) || creditScore < 0 || creditScore > 1000 ) { cout << "Pick a number between 0 - 1000:\n"; cin.clear(); cin.ignore(100, '\n'); } cout << "creditScore=" << creditScore << endl; }``````

Example test run.
 ```\$ ./a.out Type in the principal amount (<100000): banana Pick a number between 0 - 100000: -22 Pick a number between 0 - 100000: 10000000 Pick a number between 0 - 100000: 1234 principal=1234 What is your credit score?: 999 creditScore=999 ```

When you've accumulated a bit of useful functionality, then make functions out of it to keep any one function from becoming too cluttered.
 ``1234567891011121314151617181920212223242526272829303132333435`` ``````#include #include using namespace std; double getPrincipal() { double principal = 0; cout << "Type in the principal amount (<100000):\n"; // While there is input failure, or it's out of range while( !(cin >> principal) || principal < 0 || principal > 100000 ) { cout << "Pick a number between 0 - 100000:\n"; cin.clear(); cin.ignore(100, '\n'); } return principal; } int getCreditScore() { int creditScore; cout << "What is your credit score?:\n"; while( !(cin >> creditScore) || creditScore < 0 || creditScore > 1000 ) { cout << "Pick a number between 0 - 1000:\n"; cin.clear(); cin.ignore(100, '\n'); } return creditScore; } int main() { double principal = getPrincipal(); cout << "principal=" << principal << endl; int creditScore = getCreditScore(); cout << "creditScore=" << creditScore << endl; }``````