Monthly payment calculator - could not get it to work

I wrote a program that asks the user to choose different packages for a car. It then calculates monthly payment. The choosing part (switch statement) works, but the monthly payment cannot be correctly calculated. It always gives some garbage value. The monthly payment formula is programmed in line 41.

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
    char option;
    double car_price,down_payment,principal,years_amortized,months_amortized,annual_income,monthly_income,annual_interest,
monthly_interest,monthly_payment;

    cout<<
    "The base price is $16,800."<<endl<<
    "Please choose your options."<<endl<<
    "Option N: base model."<<endl<<
    "Option P: auto transmission, power windows and locks, stereo sound system.  Cost: base + 1200"<<endl<<
    "Option L: all the above plus MP3 player, security alarm, cruise control. Cost: base + 1800"<<endl<<
    "Option D: all of the above plus deluxe detailing, pin stripes, leather seats, wind bar. cost: base + 2300"<<endl<<
    "Option S: all the above plus seat heaters, Bose speakers,"<<endl<<
    "OnStar, steering wheel controls of music system, chrome rims. cost: base + 2800"<<endl;

    cin>>option;

    cout<<"Enter the downpayment amount: "<<endl;
    cin>>down_payment;

    cout<<"Enter annual interest of your loan."<<endl<<
    "For example, enter 5 for 5 percent."<<endl;
    cin>>annual_interest;

    cout<<"Enter length of loan in years."<<endl;
    cin>>years_amortized;

    cout<<"Enter your annual income."<<endl;
    cin>>annual_income;

    principal=car_price-down_payment;
    monthly_interest=(annual_interest/(12))*100;
    months_amortized=years_amortized*12;
    monthly_income=annual_income/12;
    monthly_payment=principal*(monthly_interest/(1-(pow((1+monthly_interest),(-months_amortized)))));

    switch(option)
    {
        case'N':
        car_price=16800;
        cout<<fixed<<showpoint<<setprecision(2);
        cout<<
        "The total amount is $16,800."<<endl<<
        "The monthly payment is "<<monthly_payment<<endl;

        if(monthly_income>=monthly_payment*4)
        cout<<"You are eligible for a loan.";
        else
        cout<<"You are not eligible for a loan.";
        break;

        case'P':
        car_price=18000;
        cout<<
        "The total amount is $18,000."<<endl<<
        "The monthly payment is "<<monthly_payment<<endl;

        if(monthly_income>=monthly_payment*4)
        cout<<"You are eligible for a loan.";
        else
        cout<<"You are not eligible for a loan.";
        break;

        case'L':
        car_price=18600;
        cout<<
        "The total amount is $18,600."<<endl<<
        "The monthly payment is "<<monthly_payment<<endl;

        if(monthly_income>=monthly_payment*4)
        cout<<"You are eligible for a loan.";
        else
        cout<<"You are not eligible for a loan.";
        break;

        case'D':

        car_price=19100;
        cout<<
        "The total amount is $19,100."<<endl<<
        "The monthly payment is "<<monthly_payment<<endl;

        if(monthly_income>=monthly_payment*4)
        cout<<"You are eligible for a loan.";
        else
        cout<<"You are not eligible for a loan.";
        break;

        case'S':
        car_price=19600;
        cout<<
        "The total amount is $19,600."<<endl<<
        "The monthly payment is "<<monthly_payment<<endl;
        break;

        if(monthly_income>=monthly_payment*4)
        cout<<"You are eligible for a loan.";
        else
        cout<<"You are not eligible for a loan.";
        break;
    }

    return 0;
}
should there be a negative sign in front of "months_amortized" in line 41? A negative exponent seems fishy but then again I don't know what the formula should be.
principal=car_price-down_payment;
car_price is not initialized.
Topic archived. No new replies allowed.