I am a beginner c++ student with an assignment to create a car loan calculator. I am having trouble with the calculations of the monthly payment, which I assume is because the operands are of different types in the equation? I am also not able to produce the results for the number of payments, total amount owed and total interest paid. If someone could look over my code, I would appreciate any input to help get my program working correctly!
//Date: 2/15/2011
// Programmer: Lindsay Lewis
// Description: This program computes the monthly payment for a car loan
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
// This step requires the user to input the type of vehicle
string car_type;
cout << "Enter the type of vehicle: ";
getline (cin,car_type);
// This step requires the user to input the purchase price of the car
double purchase_price;
cout << "Enter the purchase price of the car: ";
cin >> purchase_price;
// This step requires the user to input the amount of the down payment
double down_payment;
cout << "Enter the amount of your down payment: ";
cin >> down_payment;
// This step requires the user to input the number of years to pay off the car
int years;
cout << "Enter the number of years to pay off the car: ";
cin >> years;
// This step requires the user to input the interest rate
float interest_rate;
cout << "Enter the annual interest rate:";
cin >> interest_rate;
// This step calcuates the interest rate
double interest;
interest = interest_rate / 100;
// This step defines the value for the amount to be financed
double amount_financed;
amount_financed = purchase_price - down_payment ;
// This step defines the number of payments per year
int payments_year;
payments_year = 12;
// This step calculates the monthly payment
double monthly_payment;
monthly_payment = (amount_financed * (interest / payments_year)) /(1 - pow(1+\
interest / payments_year),(-payments_year * years));
// This step calculates the number of payments
double number_payments;
number_payments = years - monthly_payment;
// This step calculates the total amount owed
double total_amount_owed;
total_amount_owed = number_payments * monthly_payment;
// This step calculates the total interest paid
double total_interest_paid;
total_interest_paid = monthly_payment * number_payments - amount_financed;
// This step calculates the number of payments
double number_payments;
number_payments = years - monthly_payment;
// This step calculates the total amount owed
double total_amount_owed;
total_amount_owed = number_payments * monthly_payment;
// This step calculates the total interest paid
double total_interest_paid;
total_interest_paid = monthly_payment * number_payments - amount_financed;
cout << left;
cout << setw(40) << "Monthly Car Loan Payment Calculation" << endl;
cout << setw(40) << "========================================" << endl;
cout << setw(40) << "Type of Vehicle:" << car_type << endl;
cout << setw(40) << "Purchase Price:" << purchase_price << endl;
cout << setw(40) << "Down Payment:" << down_payment << endl;
cout << setw(40) << "Amount Financed:" << amount_financed << endl;
cout << setw(40) << "Length of Loan:" << years << endl;
cout << setw(40) << "Annual Interest Rate:" << interest_rate << endl;
cout << setw(40) << "Monthly Payment:" << monthly_payment << endl;
cout << setw(40) << "Number of Payments:" << number_payments << endl;
cout << setw(40) << "Total Amount Owed:" << total_amount_owed << endl;
cout << setw(40) << "Total Interest Paid:" << total_interest_paid << endl;
}