How to make my program run?

So, what I want is if you fit any of the following criteria, the code will go to to determine your credit score, if not, "Disqualified for loan". Then after that, check if they qualify for a bonus.

When
age = 17 it says You are qualified for $0 but I need it to say disqualified for loan.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>
using namespace std; 

 
bool promptYN(string  msg)
{    
   char entered; 
   cout << msg << endl; // in front
   cin >> entered; 
   return entered == 'y' || entered == 'Y';
} 
 
int promptInt(string  msg) 
{ 
   int number; 
   cout  << msg << endl; // in front
   cin >> number; 
   return number; 
} 
 
int  main() 
{ 
   bool homeowner, employed; 
   int  age, income, assets, creditScore, money; 
   // Do not rearrange this prompt order. 
   age = promptInt("Age: "); 
   income = promptInt("Income: "); 
   assets = promptInt("Assets: "); 
   creditScore = promptInt("Credit Score: "); 
   homeowner = promptYN("Home Owner [yn]: "); 
   employed = promptYN("Employed [yn]: ");  

   // BEGINNING OF YOUR CODE 
money = 0;
if ((age >= 18 && creditScore >= 650 && income >= 20000) || (age >= 18 && creditScore >= 650 && assets >= 30000))	    
{
	if (creditScore >= 650 && creditScore <= 699)
			money += 10000;
	else if (creditScore >= 700 && creditScore <= 749)
			money += 20000;
	else if (creditScore >= 750 && creditScore <= 799)
			money += 30000;
	else if (creditScore >= 800)
			money += 40000;
else 
	cout << "Disqualified for loan";
}	   

if (homeowner == 'y' || assets >= 50000)
{
		money += 10000;
		cout << "Qualified for $" << money;
}
else if (homeowner == 'y' && assets >= 50000 && age >= 40)
{
		money += 10000;
		cout << "Qualified for $" << money;
}
else 
		cout << "Qualified for $" << money;
   // END OF YOUR CODE
   return 0; 
}

Can you post your full assignment?
Yeah, it's a bit long though! Sorry, that I wasn't able to explain it clearly.

To qualify for a loan the applicant...

must be 18 years of age or older

and have a credit score ≥ 650

and have income of at least $20,000 or assets of at least $30,000.

If the applicant qualifies for their loan, we must determine how much they may borrow.


First, we will use the credit score:

650 to 699 qualifies for $10,000,

700 to 749 qualifies for $20,000,

750 to 799 qualifies for $30,000,

and finally anything 800 or above qualifies for $40,000.

Second, we must determine whether the applicant qualifies for a bonus $10,000 by either being a home owner or having assets of at least $50,000. The bonus is increased to $15,000 if the applicant is both these things and additionally is 40 years of age or older.



Two things to keep in mind for this project.
1) The lines marked as comment out before upload, should be commented out (i.e. put // in front) otherwise MPL tester will not work. The tester expects no output whatsoever besides one of the two outputs described below in bold.


2) Your output for nonqualifiying applicants should be

Disqualified for loan

and your output for qualifying loans should be

Qualified for $X

where X is the dollar amount .

Notice there is no period at the end of the sentences above. You shouldn't have a period either.

As an example, an output for a qualified applicant might be

Qualified for $10000

There should be no formatting for the dollar amount (e.g. just 10000, not 10,000, nor 10000.00 ) That will be true automatically if you store the amount in a variable of type int .




Use the provided code as a starter kit for your program . Remember to comment out the lines indicated before uploading to MPL. (The functions above main are there to get user input. We'll learn more about functions in Chapter 6. )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

#include <iostream>

#include <string >
using namespace std; 

 
bool promptYN(string  msg) {    

   char  entered; 
   cout  << msg << endl;   // comment  out this line before upload 
   cin >>  entered; 
   return entered == 'y'  || entered == 'Y'
 } 

 
int  promptInt(string  msg) { 
   int  number; 
   cout   << msg << endl;   // comment  out this line before upload
   cin >>  number; 
   return number; 
} 

 
int  main() { 
   bool homeowner, employed; 
   int  age, income, assets, creditScore; 
   // Do not rearrange this prompt order. 
   age = promptInt("Age: "); 
   income = promptInt("Income: "); 
   assets = promptInt("Assets: "); 
   creditScore = promptInt("Credit Score: "); 
   homeowner = promptYN("Home Owner [yn]: "); 
   employed = promptYN("Employed [yn]: ");  

   // BEGINNING OF YOUR CODE 
  

 

 

 

 

 

 

  

   // END OF YOUR CODE
   return 0; 
}


The tester verifies that your output is correct for a variety of test cases. For example if the input is

18
20000
10000
650
n
y

Then the expected output is

Qualified for $10000

Test your code outside of MPL with many possible cases (under 18 years old vs over 18 years old, home owner vs non home owner, credit score under 650 vs over 650 etc.). Verify that your program produces the output it should based on what the instructions say. If you verify a sufficient number of test cases outside of MPL, then your program will be accepted when you submit it to MPL.

More test cases to try. (You need to figure out what the output should be.)

17
20000
10000
650
n
y

_________

18
10000
50000
700
n
y

_________

41
20000
10000
650
y
y

________

18
20000
50000
650
n
y

________

18
20000
10000
850
y
y

________

The above is not a sufficient number of cases. There are at least 7 others you should try.
Last edited on
.
Last edited on
Sure! What went wrong?
1
2
3
4
5
6
7
8
9
10
11
12
13
if ((age >= 18 && creditScore >= 650 && income >= 20000) || (age >= 18 && creditScore >= 650 && assets >= 30000))	    
{
	if (creditScore >= 650 && creditScore <= 699)
			money += 10000;
	else if (creditScore >= 700 && creditScore <= 749)
			money += 20000;
	else if (creditScore >= 750 && creditScore <= 799)
			money += 30000;
	else if (creditScore >= 800)
			money += 40000;
else 
	cout << "Disqualified for loan";
}


Should be :
1
2
3
4
5
6
7
8
9
10
11
12
13
if ((age >= 18 && creditScore >= 650 && income >= 20000) || (age >= 18 && creditScore >= 650 && assets >= 30000))	    
{
	if (creditScore >= 650 && creditScore <= 699)
			money += 10000;
	else if (creditScore >= 700 && creditScore <= 749)
			money += 20000;
	else if (creditScore >= 750 && creditScore <= 799)
			money += 30000;
	else if (creditScore >= 800)
			money += 40000;
}
else 
	cout << "Disqualified for loan";


However, consider adding the variable bool qualified; for calculation.

Other thing to note :
1
2
else 
		cout << "Qualified for $" << money;


Should be :
1
2
else if(money > 0)
		cout << "Qualified for $" << money;


Note that it is not a complete fix.
Last edited on
Hello everyone,

Is it me or does everyone accept this bit of code as being correct based on the statement
Use the provided code as a starter kit for your program . Remember to comment out the lines indicated before uploading to MPL. (The functions above main are there to get user input. We'll learn more about functions in Chapter 6. )
1
2
3
4
5
6
7
bool promptYN(string  msg) {    

   char  entered; 
   cout  << msg << endl;   // comment  out this line before upload 
   cin >>  entered; 
   return entered == 'y'  || entered == 'Y'
 } 


The code says to me that the function returns a bool yet the return statement at line 6 is trying to return a char and I am not sure yet if the or part of the return even works that way. Then there is the missing semicolon at the end of line 6. Is this a typo or the way it was given to the students?

This does explain why people have been coding bool homeowner; and then trying to compare it against a char.

My opinion just food for thought.

Andy

Upon testing the code I now understand how it works. The return entered =='y' || entered == 'Y' will return 1 if 'Y' and 0 if otherwise.

And it does explain why people are coding if statements if (homeowner =='y' or homeowner == 'Y') because they think the function is returning a letter when it returns a bool.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    // BEGINNING OF YOUR CODE
    bool qualified = ( age >= 18 &&
                       creditScore >= 650 &&
                       (income >= 20000 || assets >= 30000)
                     );

    if (qualified)
    {
        //get basic loan qualification
        int loanAmt;
        if(creditScore >= 800) loanAmt = 40000;
        else if (creditScore >= 750) loanAmt = 30000;
        else if (creditScore >= 700) loanAmt = 20000;
        else loanAmt = 10000;

        //apply bonuses if eligible
        if(homeowner && (assets >= 50000) && (age >= 40))
        {
            loanAmt += 15000;
        }
        else if(homeowner || (assets >= 50000))
        {
            loanAmt += 10000;
        }

        cout << "Qualified for $" << loanAmt;
    }
    else
    {
        cout << "Disqualified for loan";
    }
    // END OF YOUR CODE 
Topic archived. No new replies allowed.