2017-10-06 26 views
0

私の目的は、ローン返済スケジュールを計算して出力することです。私が助けたいことは、方程式に原則を加え、返済スケジュールを印刷することです。私はまだ個人的な財務クラスを持っていないので、私は計算を正しく行ったのかどうか分からず、依然としてローンの概念を把握しています。自動車ローン計算(C++)

ローン返済スケジュールは、お金を置いていないと仮定した場合、自動車の全額、金利および支払いに基づいています。すべての手数料と税金は価格に含まれており、融資されます。私はまた、画面とファイルの両方に返済スケジュールを入れなければなりません - 1行に1ヶ月。 。ユーザーの信用率が800の場合、年間利率は3%になります。 700+は5%の金利を取得します。 600+は7%の金利を得る; 600未満は12%の金利を得る

私はちょうど800クレジットスコアの部分をコピーして金利を変更するので、700,600、および600未満のクレジットスコアは空白のままです。

// 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

小さなコードがあるにもかかわらず、ここに特定の質問はありません。メンタリングやコーチングが必要な場合は、[Codementor](https://www.codementor.io)、[Savvy](https://www.savvy.is)、[Hackhands](https://hackhands.com) )、[airpair](https://www.airpair.com)のいずれかを選択します。 – tadman

+0

関数とクラスを使用します。あなたのUIは、基本的なプログラム状態の表現であり、ユーザーの操作によって変更されます。 – Carbon

答えて

1

メイト、あなたは信用の下のコードを修正する必要がある - 800

  • ループ条件は
  • 間違ってcoutのあるループの後で、したがって、それは一度だけ印刷されます。
  • 原則はインクリメントまたはデクリメントされません。原則が0より小さいかどうかをチェックしていますが、原理は0より大きく設定されているため、ループは1回だけ実行されます。

このような修正が必要です。私はちょっと微調整しました。 plsは残り

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を使用すると、スペースではなくスペースが得られます。

このコードは、プロのように見えるようにするためには大きな作業が必要です。