0

当每月付款超过/等于在 *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;
}
4

1 回答 1

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;

将始终打印零

于 2013-11-11T04:32:35.323 回答