Mortgage Problem, Need help!

Hello,
I am really struggling on this problem, we have the conditions:
down pymt amount interest rate %
5,000 7.1
7,500 6.3
10,000 5.5
15,000 5.0
20,000 4.5
>20.000 4.25

I am not sure how to make the formula run using the interest rate(i) depending on how much down payment the user enters. (I know to use a switch statement but how do I get the correct i to incorporate into the formula?)
Also, if the user chooses a payment in between the amounts, the higher interest rate must be chosen. For example, if $6,0000 is the down payment, interest rate will be 7.1%. (I know a if-else statement must be made but how do I incorporate that into the switch statement?)

Please help me out , I appreciate it!


#include "math.h"
#include <iostream>
using namespace std;

int main()
{
int a = 100000;
int downpayment;
cout << "How much down payment are you making?\n" << endl;
cin >> downpayment;

double i;

switch (downpayment)
{
case 5000:
if (payment <= 5000)
cout << "7.1%\n" << endl;
break;
case 7500:
if ((payment > 5000) || (payment <= 7500 ))
cout << "6.3%\n" << endl;
break;
case 10000:
if ((payment > 7500) || (payment <= 10000))
cout << "5.5%\n" << endl;
break;
case 15000:
if ((payment >10000) || (payment <= 15000))
cout << "5%\n" << endl;
break;
case 20000:
if ((payment > 15000) || (payment <= 20000))
cout <<"4.5%\n" << endl;
break;
}

int y = 30;
int t = y*12;
double mPayment;

mPayment = ((a-downpayment) * i) / (1 - pow(1+i,-t));

cout<< "Your Monthly Payment Amount: $\n"<< mPayment;

system ("pause");
return 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
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
#include <iostream>
using namespace std;

main()
{
    int HouseCost = 100000; // Total Price for the house.
    int DownPayment = 0; // Initialize variable to 0.
    cout << "Down payment amount you are making: ";
    cin >> DownPayment;
    float Interest = 0.0; // Initialize variable to 0.0.
    
    if (DownPayment > 0 && DownPayment < 7500)
    {
        Interest = 7.1;
        cout << "Your interest rate is 7.1%." << endl;
    }

    if (DownPayment >= 7500 && DownPayment < 10000)
    {
        Interest = 6.3;
        cout << "Your interest rate is 6.3%." << endl;
    }

    if (DownPayment >= 10000 && DownPayment < 15000)
    {
        Interest = 5.5;
        cout << "Your interest rate is 5.5%." << endl;
    }

    if (DownPayment >= 15000 && DownPayment <= 20000)
    {
        Interest = 5.0;
        cout << "Your interest rate is 5.0%." << endl;
    }

    if (DownPayment == 20000)
    {
        Interest = 4.5;
        cout << "Your interest rate is 4.5%." << endl;
    }

    if (DownPayment > 20000)
    {
        Interest = 4.25;
        cout << "Your interest rate is 4.25%." << endl;
    }

    int YearDuration = 30;
    int TotalPayments = YearDuration * 12;
    float MonthlyPayment = 0.0; // Initialize variable to 0.0.
    MonthlyPayment = ((HouseCost - DownPayment) * Interest) / TotalPayments;
    cout << "Your monthly payment is: $" << MonthlyPayment << "\n" << endl;
    system("pause");
}


1. The switch statement would not work correctly, using "if statements" are more natural.
2. Don't use such confusing variable names. Make them unique and meaningful.
3. Initialize variables always, even if you plan to change them in the next line.

If you need anymore help let me know. I'll try to help as much as I can.
Topic archived. No new replies allowed.