Why won't I get this output?

I'm supposed to get disqualified for loan but instead I get qualified for $0.

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
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;

		if (homeowner == 'y' || assets >= 50000)
		{
		money += 10000;
				cout << "Qualified for $" << money;
		}
		else if (homeowner == 'y' && assets >= 50000 && age >= 40)
		{
				money += 15000;
				cout << "Qualified for $" << money;
		}
		else if (homeowner == 'n' || assets <= 50000)
				cout << "Qualified for $" << money;
		else 
				cout << "Disqualified for loan";
If you had
1
2
3
if ( homeowner == 'y' ) {}
else if ( homeowner == 'n' ) {}
else {}

you would reach the else only if homeowner is neither y nor n. You hopefully validate input and homeowner is always y or n.

If you had
1
2
3
if ( assets >= 50000 ) {}
else if ( assets <= 50000 ) {}
else {}

You would never reach the else, because a number is always less than, equal, or over some other number. (Btw, if >= is false, then assets is <50000; no point to have that '='.)

Logical or (||) is true if either operand is true (it does not even evaluate the second operand if the first is true). If your line 12 is false, then the line 22 is true.

Note that customer that would have line 17 as true will always get true on the line 12 and thus never evaluate the line 17.
Topic archived. No new replies allowed.