# Answer to Question #39227 in C++ for Ahmed

Question #39227

Write a program that obtains (from the user) the amount, interest rate and number of years of the

loan, then calculates and prints out the monthly payment. Use p, n, r and n for the variable

names when calculating this formula. You may have other variables.

loan, then calculates and prints out the monthly payment. Use p, n, r and n for the variable

names when calculating this formula. You may have other variables.

Expert's answer

`#include <cstdlib>`

#include <iostream>

#include <stdio.h>

using namespace std;

int main() {

double a;

double r;

int n; cout << "Input the data, please." << endl;

cout << "------------------------" << endl;

cout << " Amount: ";

cin >> a;

cout << " Interest rate: ";

cin >> r;

cout << " Number of years: ";

cin >> n;

double m = (a + a * r / 100) / (12 * n);

cout.setf(ios::fixed);

cout.precision(2);

cout << endl << "Monthly payment: " << m << endl;

getchar(); getchar();

return 0;

}

## Comments

## Leave a comment