Sooo, whenever my input hits the first and second if statement, my outcome is loan += 10k when it should be 15k.
I was told that "The 10K condition is weaker than the 15K condition, i.e. if the 15K condition is true then so is the 10K condition. So you want to test for the 15K condition first. Otherwise you never reach the 15K condition."
I'm not quite sure what this means, could someone give me a step in the correct direction?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
if (loan >= 10000) // If loan is greater than or equal to 10000... (Reqs. for bonus)
{
if (homeowner == 'y' && assets >= 50000 && age >= 40 || homeowner == 'Y' && assets >= 50000 && age >= 40 ) // Reqs. for 15000 bonus
{
loan += 15000;
cout << "Qualified for $" << loan;
}
elseif ((homeowner == 'y') || (homeowner == 'Y') || (assets >= 50000)) // Reqs. for 10000 bonus
{
loan += 10000;
cout << "Qualified for $" << loan;
}
else
cout << "Qualified for $" << loan;
}
I just see that you have not fixed any of the problems we pointed out.
kemort wrote:
If homeowner is boolean then it can only take values of true (1) or false (0). A char value for homeowner would not be appropriate. Comparing homeowner to a char probably always returns false, or even worse, undefined behaviour.
ASCII code for y is 121. Non-zero numbers are true. I don't think that's the problem bc it still adds up. If that's not the case, I'm not sure how it would determine whether y or n is t or f.
ASCII code for y is 121. Non-zero numbers are true. I don't think that's the problem bc it still adds up. If that's not the case, I'm not sure how it would determine whether y or n is t or f.
No, a boolean cannot store a value more than 1.
Forget the value 121.
Your program is now correct. However, some of your code is not very efficient.
You need to fix a couple of things (in other words, tweaks or something like that).
Yes, I'm happy you are able to solve the assignment.
A couple of things :
- homeowner == 1 (To be more precise, it should be homeowner == true)
- if (loan >= 10000) is redundant.
- You only need to output cout << "Qualified for $" << loan; once. Since the person is already qualified for loan.