Note that there are some explanatory texts on larger screens.

plurals
  1. POObtaining incorrect data using class object in different class
    primarykey
    data
    text
    <p>hey guys im writing a loan program here using two classes. I declare an object from my "MortCalc" Class in My LoanOfficer Class. The loan officer class is to determine whether a user qualifies for a loan or not a user enters the principal of a loan, monthly income, and monthly expenses. The Loan officer class then does a calculation and reports back to the user if the loan was approved using one rule. The rule is this: if the monthly payment of the loan( which is obtained from my MortCalc Class) and monthly expenses total is greater than 50% of the monthly income then the loan is not approved. The problem I've encountered is with calculating this. I try to store the calculation in a "rule" variable but it always equals 100 thus never approving the loan! obviously im doing something wrong here but i can't figure out what. here is my code:</p> <p><strong>LoanOfficer.h</strong> </p> <pre><code>class LoanOfficer { //private class variables private: MortCalc mc; double intRate; double monthlyIncome; double term; double monExpenses, principal; double rule; bool bLoanApprove, bOpen; string userName, fileName,lenderName; string loanOfficer, Welcome; int counter; void calculate(); </code></pre> <p><strong>LoanOfficer.cpp</strong></p> <pre><code>LoanOfficer::LoanOfficer() { //initializing variables; intRate = 4.1; term = 30; counter=1; principal=0; lenderName="John's Bank"; Welcome =""; calculate(); } void LoanOfficer::calculate() { rule = ((mc.GetMonPymt() + monExpenses) / monthlyIncome)* 100; //i have a getter in my Mortcalc class which get's the monthly Payment. } bool LoanOfficer::isApproved() { if(rule&gt;50) { bLoanApprove = true; } else{ bLoanApprove = false; } return bLoanApprove; } string LoanOfficer::getApproval() { if(bLoanApprove==true) { stringstream ss; ss&lt;&lt;"\n\nLoan Approval Status: Yes" &lt;&lt;"\nLoan amount: " &lt;&lt;principal &lt;&lt;"\nInterest Rate: " &lt;&lt;intRate &lt;&lt;"\nMonthly Payment: " &lt;&lt;monPayment &lt;&lt;"\nTotalLoan: " &lt;&lt;mc.GetTotalLoan() &lt;&lt;"\nTotal Interest" &lt;&lt;mc.GetTotalInt() &lt;&lt;"\n\nCongratulations We're looking to do business with you " &lt;&lt;userName&lt;&lt;"!"; loanOfficer = ss.str(); } else { stringstream ss; ss&lt;&lt;"\n\nLoan Approval Status: No" &lt;&lt;"\n\n Income vs Montly Payment and expenses does not meet " &lt;&lt;"\n the 50% criteria net income that is necessary for this" &lt;&lt;"\n institution to approve this loan"; loanOfficer = ss.str(); } return loanOfficer; } void LoanOfficer::setPrincipal(double p) { mc.setPrin(p); principal = p; } bool LoanOfficer::isOpen() { return bOpen; } void LoanOfficer::setMonInc(double mi) { monthlyIncome = mi; } void LoanOfficer::setExpenses(double ex) { monExpenses = ex; } void LoanOfficer::setAppName(string n) { userName = n; } string LoanOfficer::getFilename() { return fileName; } string LoanOfficer::getIntro() { stringstream ss; ss&lt;&lt;"Hi Welcome to " &lt;&lt;lenderName &lt;&lt;"\n Please enter your information below to see if you're approved for a loan." &lt;&lt;"\nWe have a fixed interest rate of 4.1 and term of loan is 30 years." &lt;&lt;"\nThe way we determine our loan approvals is by adding loan payment and monthly expenses," &lt;&lt;"\nand that is greater than 50% of your monthly income the loan is notapproved.\n\n"; Welcome = ss.str(); return Welcome; } void LoanOfficer::writeStatus() { stringstream ss; ss&lt;&lt;userName&lt;&lt;"_"&lt;&lt;counter&lt;&lt;".txt"; fileName = ss.str(); ofstream receiptOut; receiptOut.open(fileName.c_str()); //Writing report setting precision to 2 decimal places //returning true if able to write receipt. receiptOut&lt;&lt;" CUSTOMER LOAN INFORMATION " &lt;&lt;month+1&lt;&lt;"/"&lt;&lt;day&lt;&lt;"/"&lt;&lt;year+1900&lt;&lt;"\n\n" &lt;&lt;"********************************" &lt;&lt;"\n Your Loan Information: " &lt;&lt; "\n\n Principal: "&lt;&lt;"$" &lt;&lt; fixed &lt;&lt; setprecision (2) &lt;&lt; principal &lt;&lt; "\n\n Interest rate: "&lt;&lt; fixed &lt;&lt; setprecision (2) &lt;&lt; intRate &lt;&lt; "%" &lt;&lt; "\n\n Monthly Payment: "&lt;&lt;"$" &lt;&lt; fixed &lt;&lt; setprecision (2) &lt;&lt; mc.GetMonPymt() //here it obtains the correct monthly payment. I've checked through //debugging. &lt;&lt; "\n\n Total Interest paid: " &lt;&lt;"$"&lt;&lt; fixed &lt;&lt; setprecision (2) &lt;&lt; mc.GetTotalInt() &lt;&lt;"\n\n Total Cost of the Loan: "&lt;&lt;"$" &lt;&lt; fixed &lt;&lt; setprecision (2) &lt;&lt; mc.GetTotalLoan() &lt;&lt;"\n*********************************" &lt;&lt;"\n\n\nThank You for using my calculator. Have a Nice Day." &lt;&lt;"\n****************************************************"; receiptOut.close(); counter++; } </code></pre> <p><strong>main.cpp</strong></p> <pre><code>double principal,monthlyIncome,monthlyExpenses; string name, answer; string fAnswer //class object LoanOfficer lo; cout&lt;&lt;lo.getIntro(); cout&lt;&lt;"Please enter your name: "; cin&gt;&gt;name; //passing name to setName class method. lo.setAppName(name); //start of do loop do { //presenting the user a menu accessed from otherFunctions.cpp //checking which choice user entered with switch statements cout&lt;&lt;"\nPlease enter the amount you want to borrow: "; cin&gt;&gt;principal; cin.ignore(); lo.setPrincipal(principal); cout&lt;&lt;"\nPlease enter your monthly income after taxes: "; cin&gt;&gt;monthlyIncome; cin.ignore(); lo.setMonInc(monthlyIncome); cout&lt;&lt;"\nPlease enter your monthly expenses: "; cin&gt;&gt;monthlyExpenses; cin.ignore(); lo.setExpenses(monthlyExpenses); cout&lt;&lt;lo.getApproval(); cout&lt;&lt;"\n\n Would you like to write a file? Enter y for yes and n for no\n"; cin&gt;&gt;fAnswer; if(fAnswer =="y") { lo.writeStatus(); cout&lt;&lt;"\n\nReport is located in: " &lt;&lt;lo.getFilename(); } else { cout&lt;&lt;"\n\nNo report printed out."; } //ask if user would like to do another cout&lt;&lt;"\n\nWould you like to do another loan? Enter y for yes and n for no\n"; cin&gt;&gt;answer; cout&lt;&lt;"\n"; }while(answer =="y"); //end do/while //Goodbye message { cout &lt;&lt;"\n Thanks for calculating. Goodbye!\n\n"; //when loop is done } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload