【发布时间】:2020-03-18 13:42:35
【问题描述】:
我需要帮助来计算现值。用户将输入:支付金额(payamt)、期限(trm)和利率(intrte)。我在计算以下等式时遇到问题:
现值=支付金额*((1-(1+利息)^-期限)/利率)
这是我目前的代码:
#include <iostream>
using namespace std;
int main()
{
int trm = 0
;
double intrte = 0.0
;
float payamt = 0.0,
presVal = 1
;
char
response = '\0'
;
cout << "Would you like to compute a present value? Enter Y for yes; N for no.";
cin >> response;
if (response != 'Y') {
return 0;
}
cout << "\nPayment Amount: $"; //payment in $ and cents for each year
cin >> payamt;
cout << "\nTerm (in years): "; //term number of years of payments
cin >> trm;
cout << "\nInterest Rate (between 0 and 100): ";//interest rate
cin >> intrte;
cout << "\n\nThe present value for a payment amount of $" << payamt
<< " and an interest rate of " << intrte
<< "%, and a term of " << trm
<< " years is $" << presVal
<< ".\n\n" << endl;
presVal == payamt * (1 - ((1 + intrte), (-trm)))/intrte;
}
【问题讨论】:
-
您能详细说明您遇到了什么问题吗?编译错误?运行时错误?错误信息是什么?
-
在最后一行,您使用“==”比较 presVal,如果要将 te 公式分配给 presVal,则应使用“=”