我正在尝试编写代码来计算项目的月薪。

这是我得到的公式:

(Rate + Rate/((1+Rate)^Months)-1) * Principle


根据此公式,RateRate/1200,例如,如果速率是7%,它将是7/1200,即0.00583333333。我试图在程序中输入确切的数字0.00583333333,但随后出现错误“非法使用浮点数”。

这是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    float r;
    int m, y;
    int p;
    //int mp;


    printf("Enter Rate: ");
    scanf("%d", &r);
    r = r%1200;

    printf("Enter number of years: ");
    scanf("%d", &y);
    m = y*12;

    printf("%.10lf\n",r);
    printf("%d",m);

    return 0;
}


如何使0.00583333333成为程序中计算的一部分?

最佳答案

尝试通过scanf("%d", &r);更改scanf("%f", &r);并通过r = r%1200更改r = r/1200

关于c - 非法使用浮点数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30386700/

10-11 23:07
查看更多