我正在尝试编写一个计算项目月工资的代码。
这是我给出的公式:
(Rate + Rate/((1+Rate)^Months)-1) * Principle
根据此公式, Rate
为Rate/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
成为我在计划中计算的一部分?
答案 0 :(得分:4)
尝试按scanf("%d", &r);
更改scanf("%f", &r);
,r = r%1200
更改r = r/1200