2016-06-09 9 views
0

Ich habe die my-Gleichung kompiliert und ausgeführt und es scheint vollständig von einer Benutzeroberfläche und von der Kompilierungsseite zu funktionieren, aber die Gleichung verliert sich irgendwo in der Erbschaft. Irgendwelche Gedanken?Mortgage Calc Ausgaben -e Wert

#include <iostream> 
#include <cmath> 

using namespace std; 
class MortgageCalc 
{ 
    private: 
     float loan, interest, term; 
     int years; 
     float monthlyDue, totalDue, totalInt; 
    public: 
     MortgageCalc() = default; 
     void setData(float, float, float); 
     float setLoan(void); //mutator 
     float setIntrest(void);  //mutator 
     float setYears(void); 
     float setTerm(); //mutator 
     float getMonthlyDue(); 
     float getTotalDue(); 
     float getTotalInt(); 
}; 

void MortgageCalc::setData(float l, float i, float y) 
{ 
    loan = l; 
    interest = i; 
    years = y; 
} 

float MortgageCalc::setLoan(void) 
{ 
    return loan; 
} 

float MortgageCalc::setIntrest(void) 
{ 
    return interest; 
} 

float MortgageCalc::setYears(void) 
{ 
    return years; 
} 

float MortgageCalc::setTerm() 
{ 
    term = pow((1 + ((interest/100)/12)), (12 * years)); //simple interest calculation with power calc to establish whole number translation 
    return term; 
} 

float MortgageCalc::getMonthlyDue() 
{ 
    monthlyDue = (loan * ((interest/100)/12) * term)/(term - 1); 
    return monthlyDue; 
} 

float MortgageCalc::getTotalDue() 
{ 
    totalDue = (getMonthlyDue() * (years * 12)); 
    return totalDue; 
} 

float MortgageCalc::getTotalInt() 
{ 
    totalInt = (getTotalDue() - loan); 
    return totalInt; 
} 

int main() 
{ 
    MortgageCalc mort1; 
    int choice = 0; 
    int years = 0; 
    double term(0) , loan(0), interest(0); 

    cout << "Enter the total loan amount on your mortgage loan: $"; //established loan variable 
     cin >> loan; 

    cout << "Enter the interest rate (in whole #'s only): "; //establishes interest rate variable 
     cin >> interest; 

    cout << "Enter the length of the loan in years: "; //establishes term of payments 
     cin >> years; 

    mort1.setData(loan, interest, years); 

    while (choice != 3) //loop for menu options and clean function exit 
    { 
     cout << endl; 
     cout << "Program to Calculate Mortgage Payments" << endl << 
       "1. Monthly Payment" << endl << 
       "2. Total Payment" << endl << 
       "3. Exit" << endl << endl << 
       "Enter an option above: "; 
     cin >> choice; 

     if (choice == 1) 
      cout << "Monthly payment due is " << mort1.getMonthlyDue() << "." << endl; 
     else if (choice == 2) 
      cout << "Total amount for entire loan payments plus interest is $" << mort1.getTotalDue() << "." << endl << 
        "Total Interest Paid for this loan amount $" << mort1.getTotalInt() << "." << endl; 
    } 
    return 0; 
} 

Hier wird der Ausgabetext ist:

Enter the total Loan Amount: $100,000 
Enter the interest Rate: 5 
Enter the length of the loan: 10 
Program to calculate mort payments 
1. Monthly Payments 
2. Total Payments 
3. Exit Enter and Option Above: 1 
Monthly Payment Due is: -1.56868e-036 
+0

Was ist Ihre Eingabe, erwartete Ausgabe und die beobachtete Ausgabe? –

+0

@RSahu wenn ich 100000, 5, 10 ..... Es sollte monatliche Zahlung ausgeben $ 1060.66 Gesamt Zahlung mit Interesse $ 127279.00 – haynstyle

+0

Bitte fügen Sie den Text (keine Bildschirmaufnahme oder Bild) Ihrer Ausgabe zu der Frage. – drescherjm

Antwort

0

Danke für die Unterstützung auf diesem, fand ich, dass der Begriff Anruf aus wurde außerhalb des Kindes Bezug gebracht werden und somit konnte die Aktualisierung Feld und geben Sie die richtige Eingabe zurück.

#include <iostream> 
#include <cmath> 

using namespace std; 
class MortgageCalc 
{ 
    private: 
     float loan, interest, term; 
     int years; 
     float monthlyDue, totalDue, totalInt; 
    public: 
     MortgageCalc() = default; 
     void setData(float, float, float); 
     float setLoan(void); //mutator 
     float setIntrest(void);  //mutator 
     float setYears(void); 
     float setTerm(); //mutator 
     float getMonthlyDue(); 
     float getTotalDue(); 
     float getTotalInt(); 
}; 

void MortgageCalc::setData(float l, float i, float y) 
{ //copies arguments from input to private members 
    loan = l; 
    interest = i; 
    years = y; 
    setTerm(); 
} 

float MortgageCalc::setTerm() 
{ //simple interest calculation with power calc to establish whole number translation 
    term = pow((1 + ((interest/100)/12)), (12 * years)); 
    return term; 
} 

float MortgageCalc::setLoan(void) 
{ //returns loan amt to private member 
    return loan; 
} 

float MortgageCalc::setIntrest(void) 
{ //returns interest amt to private member 
    return interest; 
} 

float MortgageCalc::setYears(void) 
{ //returns years to private member 
    return years; 
} 



float MortgageCalc::getMonthlyDue() 
{ //simple cal to output monthly 
    monthlyDue = (loan * ((interest/100)/12) * term)/(term - 1); 
    return monthlyDue; 
} 

float MortgageCalc::getTotalDue() 
{ 
    totalDue = (getMonthlyDue() * (years * 12)); 
    return totalDue; 
} 

float MortgageCalc::getTotalInt() 
{ 
    totalInt = (getTotalDue() - loan); 
    return totalInt; 
} 

int main() 
{ 
    MortgageCalc mort1; 
    int choice = 0; 
    int years = 0; 
    double term(0) , loan(0), interest(0); 

    cout << "Enter the total loan amount on your mortgage loan: $"; //established loan variable 
     cin >> loan; 

    cout << "Enter the interest rate (in whole #'s only): "; //establishes interest rate variable 
     cin >> interest; 

    cout << "Enter the length of the loan in years: "; //establishes term of payments 
     cin >> years; 

    mort1.setData(loan, interest, years); 

    while (choice != 3) //loop for menu options and clean function exit 
    { 
     cout << endl; 
     cout << "Program to Calculate Mortgage Payments" << endl << 
       "1. Monthly Payment" << endl << 
       "2. Total Payment" << endl << 
       "3. Exit" << endl << endl << 
       "Enter an option above: "; 
     cin >> choice; 

     if (choice == 1) 
      cout << "Monthly payment due is " << mort1.getMonthlyDue() << "." << endl; 
     else if (choice == 2) 
      cout << "Total amount for entire loan payments plus interest is $" << mort1.getTotalDue() << "." << endl << 
        "Total Interest Paid for this loan amount $" << mort1.getTotalInt() << "." << endl; 
    } 
    return 0; 
}