这个摊销公式的适当循环是什么?

时间:2013-11-11 03:59:24

标签: c++ formula amortization

当每月付款超过/等于* monthly_payment *函数中找到的30%金额时,我正在尝试打印变量* loan_Amt *。这是我第一次尝试用函数编写c ++程序!

#include<iostream>
#include<conio.h>
#include<string>
#include<iomanip>
#include<math.h>
using namespace std;

double monthly_Payment (double amt_Amt)
{
    double r;
    r = ( amt_Amt/ 12) * 30/100;
    return (r);
}

    double interest_Calculate(double interest_Amt)
{
    double r;
    r = (interest_Amt * .010);
    return (r);
}

//double loan_Calculate()
//{
//int x = interest_Calculate(interest_Rate);
//double monthly = (loan_Amt * x) / (1 - pow(1.0 + i,-(12*30)));
//for (((int loan_Amt = 20000) * (x/12)) / pow(1.0 + i,-(12*30)); loan_Amt>0; loan_Amt++);

//}

int main()
{

double gross_Salary;
double interest_Rate;
int x;
int i;
double monthly;

std::cout << "Please enter your yearly gross salary:";
std::cin >> gross_Salary;

std::cout << "Please enter an interest rate:";
std::cin >> interest_Rate;
int z;
z = monthly_Payment (gross_Salary);
std::cout << "The target (30 percent of monthly salary) monthly payment range is:" << z;
for ( int loan_Amt = 0; loan_Amt <= 5000000; x++ ) {
    do {
    x = interest_Calculate(interest_Rate);
     monthly = (loan_Amt * x) / (1 - pow(1.0 + x,-(12*30)));
     std::cout << loan_Amt;
    } while (monthly >= z );
}

getch();
return 0;
}

1 个答案:

答案 0 :(得分:0)

for循环有问题,我想,

for ( int loan_Amt = 0; loan_Amt <= 5000000; x++ ) {
do {
x = interest_Calculate(interest_Rate);
 monthly = (loan_Amt * x) / (1 - pow(1.0 + x,-(12*30)));
 std::cout << loan_Amt;
} while (monthly >= z );

}

loan_Amt永远不会改变它的值,所以这是一个无限循环。 do-while循环中的这一行,

std::cout << loan_Amt;

将始终打印零