我无法弄清楚如何计算出一个人有资格获得贷款的金额以及需要多少年的逻辑等式/数学。下面粗体文字是我被困的地方。任何想法都将受到赞赏,包括公式建议。
完整的程序规范:
输入客户的年收入,贷款年数(贷款期限),贷款金额(贷款金额)和客户状态(P表示优先或R表示常规)。如果客户满足以下任一条件,则批准贷款。对于普通客户 - 贷款金额除以贷款期间的月数&lt; =客户月收入的10%。或者,如果客户是优选客户,则贷款金额除以贷款期间的月数<=客户年收入的1%。输出批准或不批准。
我无法弄清楚:
如果贷款被拒绝(2)告诉客户贷款可能基于当前收入的最高金额(3)期限多长(向上舍入到最近的一年)必须以当前收入来批准贷款。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double income, preferred_validation, regular_validation, years, loan_amount, monthlyIncome, annualIncomeTest, max_amount, request_amount;
char status;
cout<<"Please enter the annual income of the customer: ";
cin>>income;
cout<<"\nPlease enter the number of years of the loan: ";
cin>>years;
cout<<"\nPlease enter the amount of the loan: ";
cin>>loan_amount;
cout<<"\nCustomer status: P - Preferred R - Regular."<<endl;
cout<<"Please enter the customer's status: ";
cin>>status;
if(status != 'P' || 'R')
{
status='R';
cout<<"\n\nThe customer status code you input does not match one of the choices.\nThe calculations that follow are based on the applicant being a Regular customer."<<endl;
}
if(status=='R')
{
regular_validation=loan_amount/(years*12);
monthlyIncome=((income/12)*.10);
if(regular_validation<=monthlyIncome)
{
cout<<"\nThis loan is approved.";
}
else
{
cout<<"\nThis loan is disapproved.";
}
}
else if(status=='P')
{
preferred_validation=loan_amount/(years*12);
annualIncomeTest=income*.01;
if(preferred_validation<=annualIncomeTest)
{
cout<<"\nThis loan is approved.";
}
else
{
cout<<"\nThis loan is disapproved."<<endl;
max_amount=???;
cout<<"As a preferred customer, the largest loan you qualify for is "<<max_amount<<" or you can get the requested amount of "<<loan_amount<<" by increasing the loan period to "<<years<<" years.";
}
}
else
{
cout<<"Restart and enter your customer status.";
}
cin.get();
cin.get();
return 0;
}
答案 0 :(得分:3)
if(status != 'P' || 'R')
应该是:
if(status != 'P' && status != 'R')
显然你在preferred_validation <=
annualIncomeTest`时拒绝贷款,那么max_amount应该是annualIncomeTest?
max_amount= annualIncomeTest;