非法使用浮点

时间:2015-05-22 00:48:20

标签: c

我正在尝试编写一个计算项目月工资的代码。

这是我给出的公式:

(Rate + Rate/((1+Rate)^Months)-1) * Principle
根据此公式,

RateRate/1200,例如,如果费率为7%,则7/12000.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成为我在计划中计算的一部分?

1 个答案:

答案 0 :(得分:4)

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