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.
Need:1. Ask for an amount(principle):
(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%)
Good-690-719(4.01%-6.50)Fair-630-689(rate 6.51%-8.75)Bad-300-629(rate 8.76%-10.50%).
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.
// Week 1
#include<iostream>
#include<cmath>
#include<iomanip>
usingnamespace 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;
}
#include<iostream>
#include<cmath>
#include<iomanip>
usingnamespace 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.
{
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:
1 2 3 4 5
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.
Make one loop work first, then add a second and third loop when you understand what's going on.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<iostream>
#include<iomanip>
usingnamespace 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;
}
#include<iostream>
#include<iomanip>
usingnamespace 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.
#include<iostream>
#include<iomanip>
usingnamespace 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;
}