通话中的参数太少

时间:2018-09-27 22:04:13

标签: c++

我正在做一个关于抵押率的项目,但是我无法让pow函数正常工作,它一直在说我需要更多的单词,只是想感觉到它,这样我就可以发布它:

double loanAmount = 0.0;
double annualIntrest = 0.0;
double loanDuration = 0.0;
double monthlyIncome = 0.0;
double payMent = 0.0;
double monthlyIntrest = 0.0;
double totalIntrest = 0.0;
double percentTotal = 0.0;
int const PERCENTAGE = 100;

// *** Your program goes here ***
printf("Enter the amount of the loan: $");
scanf("%lf", &loanAmount);
if (loanAmount > 0.0) {
    printf("Enter the annual interest rate (8.0 = 8.0%%): ");
    scanf("%lf", &annualIntrest);

    if ((annualIntrest >= 1.0) && (annualIntrest <= 20.0)) {
        printf("Enter the length of the loan (in years): ");
        scanf("%lf", &loanDuration);

        if ((loanDuration >= 1) && (loanDuration <= 30)) {
            printf("Enter your monthly gross income: $");
            scanf("%lf", &monthlyIncome);


            if (monthlyIncome > 0.0) {
                percentTotal = annualIntrest / PERCENTAGE;
                monthlyIntrest = (percentTotal / 12);
                payMent = loanAmount * monthlyIntrest / (1 - (1 + monthlyIntrest));
                pow(payMent, loanDuration);
                totalIntrest = loanDuration * payMent - loanAmount;


                printf("%.2lf\n", totalIntrest);
            }
            else {
                printf("Monthly income must be greater than $0.00");
                printf("\n");
            }
        }
        else {
            printf("Loan duration must be between 1 year and 30 years");
            printf("\n");
        }
    }
    else {
        printf("Annual interest rate must be greater than 1.0%% and less than 20.0%%");
        printf("\n");
    }
}
else {
    printf("Loan amount must be greater than $0.00");
    printf("\n");
}

分配规范以及要实现的公式:

enter image description here

2 个答案:

答案 0 :(得分:2)

让我们休息

pow(payMent = loanAmount * monthlyIntrest / (1 - (1 + monthlyIntrest),-loanDuration));

往下一点。

payMent = loanAmount * monthlyIntrest / (1 - (1 + monthlyIntrest),-loanDuration)

是一个论点。应该将其分为两个参数的逗号在方括号内。您可能是说

payMent = loanAmount * monthlyIntrest / (1 - (1 + monthlyIntrest)), -loanDuration

但即使这是狡猾的。您可以将赋值放在函数调用中,但是为什么呢?您会因为编写不必要的神秘代码而一无所获,并失去工作机会。

理智的程序员写道

payMent = loanAmount * monthlyIntrest / (1 - (1 + monthlyIntrest));
pow(payMent,-loanDuration);

但是

(1 - (1 + monthlyIntrest))

看起来不太正确。它解析为monthlyIntrest,因此很可能在公式中至少键入了一个附加的转录错误。

答案 1 :(得分:1)

在您的示例中,

  

pow(payMent = loanAmount * monthIntrest /(1-(1 + monthIntrest),-loanDuration));

payMent已分配

loanAmount * monthlyIntrest / (1 - (1 + monthlyIntrest), -loanDuration

计算结果为

-loanDuration

有效地

payMent = -loanDuration

然后用作pow()的参数。使用括号将分配与第二个参数分开:

pow((payMent = loanAmount * monthlyIntrest / (1 - (1 + monthlyIntrest)),-loanDuration);
    ^                                                                 ^