Need help with this source code!

This is the problem:



This is my code:

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
#include <iostream>
using namespace std;
int main()
{
    //declaration
    int months;
    double amount_needed,face_value,monthly_payment;
    double rate;

    //input
    
    cout <<"Enter amount needed\n";
    cin >> amount_needed;
    cout <<"Enter the interest rate\n";
    cin >> rate;
    cout <<"Enter the duration of the loan\n";
    cin >> months;
    
    //calculation
    
    face_value=amount_needed/(1-rate*(months/12));
    monthly_payment=face_value/months;
    
    //output
    
    cout <<"Your loan amount should be $" << face_value
    << "to get $" << amount_needed << endl;
    cout << "You'll pay $" <<monthly_payment<< "per month\n";
    
    return 0;
    
    
}




I just need to know if the equations are correct or if theres a error.
Thanks
Last edited on
Please use code tags so we can refer to line numbers.

Run a few test using known values and see if the output is what is expected.

I do not understand your formula.

Interest = Principle * Rate* Time
How do i use the code tags.Im new to this site.
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
#include <iostream>
using namespace std;
int main()
{
    //declaration
    int months;
    double amount_needed,face_value,monthly_payment;
    double rate;

    //input
    
    cout <<"Enter amount needed\n";
    cin >> amount_needed;
    cout <<"Enter the interest rate\n";
    cin >> rate;
    cout <<"Enter the duration of the loan\n";
    cin >> months;
    
    //calculation
    
    face_value=amount_needed/(1-rate*(months/12));
    monthly_payment=face_value/months;
    
    //output
    
    cout <<"Your loan amount should be $" << face_value
    << "to get $" << amount_needed << endl;
    cout << "You'll pay $" <<monthly_payment<< "per month\n";
    
    return 0;
    
    
}
Just click edit on your original post, highlight your code and under the format option is a pair of <> which is for source code.
Already did it. The program run but i think i have a logic error.
Topic archived. No new replies allowed.