Need guidance editing a program

This is a discussion on Need guidance editing a program within the C++ Programming forums, part of the General Programming Boards category; I am a beginner c++ student with an assignment to create a car loan calculator. I am having trouble with ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    12

    Need guidance editing a program

    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;

    }

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    1. You declare number_payments, total_amount_paid, and total_interest_paid twice. You don't need to declare variable whenever you assign it.
    2. pow() takes 2 arguments, you pass only 1 - check your braces near:
    monthly_payment = (...)
    3. main() should return 0.
    I never put signature, but I decided to make an exception.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    We would appreciate if you took the time to read topics like << !! Posting Code? Read this First !! >>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a Battleship Program
    By HBlakeH in forum C Programming
    Replies: 1
    Last Post: 12-05-2010, 10:13 PM
  2. Homework Help, simple program, unsure newbie :(
    By Aslan14 in forum C Programming
    Replies: 13
    Last Post: 11-14-2010, 04:07 PM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. Movie Editing Program
    By digdug4life in forum Tech Board
    Replies: 1
    Last Post: 12-16-2006, 09:12 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21