汽车贷款计算(C ++)

时间:2017-10-06 03:01:38

标签: c++ calculation

我的目标是计算并输出贷款偿还时间表。我想得到帮助的是将原则添加到等式中并打印出还款计划。我不确定我是否做了正确的计算,因为我还没有个人理财课程,并且仍然掌握贷款的概念。

贷款偿还时间表基于汽车的全价,利率和付款,假设没有放下资金。所有费用和税费都包含在房价内,并将获得融资。我还必须将还款计划同时放在屏幕和文件中 - 每行一个月。 。如果用户的信用率为800,则他们的年利率为3%; 700+获得5%的利率; 600+获得7%的利率;不到600得到12%的利率

700,600及600以下的信用评分是空白的,因为我只想再次复制800学分,但会改变利率。

// This program calculates a loan depending on the pereson's credit score
// how much they can pay per month. It almost outputs the month, principal,
// payment, interest, and the money that's been applied

#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;

int main() {
    int month = 0, creditScore = 0, whichCar;
    double principle, payment = 0.0, interestPaid, applied, interestRate;

    cout << fixed << setprecision(2) << showpoint;      // Sets total or whatever to 2 decimal points
    cout << "---------------------------------------------" << endl;    // Displays welcome banner
    cout << "|                                           |" << endl;
    cout << "|     JOLLY GOOD SHOW WE HAVE CARS AYEEE    |" << endl;
    cout << "|                                           |" << endl;
    cout << "---------------------------------------------" << endl;
    cout << endl;
    cout << "Hey, I see you want a car. You can only purchase one car though." << endl;
    cout << endl;
    cout << "1. Furawree: $6,969.69" << endl;           // Displays menu of autos
    cout << "2. Buggee: $420,420.420" << endl;
    cout << "3. Sedon: $900" << endl;
    cout << "4. Truck: $900,000.90" << endl;
    cout << "5. Couppee: $22,222.22" << endl;
    cout << endl;
    cout << "Which car would you like to purchase?" << endl;    // Asks user car type and user inputs car #
    cout << "Please enter the number of the car: ";
    cin >> whichCar;
    cout << endl;

    switch(whichCar) {      // If user choses a number 1-5, then it asks them how much they can pay each month for the car and their credit score
        case 1:                         // FURAWREE
            principle = 6969.69;
                break;
        case 2:                         // BUGGEE
            principle = 420420.42;
            break;
        case 3:                         // SEDON
            principle = 900;
            break;
        case 4:                         // TRUCK
            principle = 900000.90;
            break;
        case 5:                         // COUPPEE
            principle = 22222.22;
            break;
        default:                        // If user doesn't pick a number from 1-5

            cout << "Yea uhhmmm we don't have that sorry, go away." << endl;
    }
    cout << "Please enter how much you can pay each month for this Furawree: ";
    cin >> payment;
    cout << "Please enter your credit score: ";
    cin >> creditScore;
        if (creditScore >= 800) {
            interestRate = .03 / 12;
            do {
                interestPaid = principle * interestRate;
                applied = payment - interestPaid;
                month++;
            } while (principle < 0) ;
                cout << "Month  " << " Principle " << " Payment " << " Interest " << " Applied " << endl;
                cout << month << "       $" << principle << "      $" << payment << "   " << interestPaid << "     $" << applied << endl;

    } else if (creditScore >= 700) {
            // Will be copied from the 800 credit score

    } else if (creditScore >= 600) {
            // Will be copied from the 800 credit score

    } else {
            // Will be copied from the 800 credit score

    }

    cout << endl;
    cout << endl;
    cout << "Your payment: $" << payment << endl;
    cout << "Your credit score: " << creditScore << endl;
    cout << endl;
    cout << endl;

    system("pause");
    return 0;
}

1 个答案:

答案 0 :(得分:1)

Mate,你需要在信用证下修改代码 - 800.

  • 循环条件不正确
  • cout在循环之后,因此它只会打印一次。
  • 原则不是递增也不是递减。并且您正在检查原则是否小于0,但是原则设置为大于0.因此循环将仅执行一次。

你需要修复这样的事情。我稍微调整了一下。请修复其余的

    if (creditScore >= 800) {
        interestRate = .03 / 12;
        cout << "Month  " << " Principle " << " Payment " << " Interest " << " Applied " << endl;
        cout <<"-------------------------------------------------------" << endl;
        do {
                interestPaid = principle * interestRate;
                applied = payment - interestPaid;
                principle = principle - applied;
                cout << month << "       $" << principle << "      $" << payment << "   " << interestPaid << "     $" << applied << endl;

                month++;
        } while (principle > 0) ;

} else if (creditScore >= 700) {

注意: - 上面的代码不遵循任何面向对象的概念。它甚至不是函数式编程。介绍减少头痛的类,方法,它将有助于调试。 使用\t\t来获取空格而不是空格。

此代码需要进行大量重新设计才能使其看起来更专业。