意图:该程序向用户询问当前在其银行账户中的金额,APR和年数。输出是显示用户指定年份累计利息的金额的开始和结束。C程序:计算利息
问题:我试图找到一种方法来正确添加利息,因为现在的指定年数我正在做的是乘以(当前银行账户的金额*利率*年)我知道这是不对的,我觉得我需要积累利率循环从一年到下一个,这就是我需要help.Thanks这里是下面我当前的代码...
代码
#include <stdio.h>
#include <stdlib.h>
float getPV()
{
float d;
float start;
printf("Start: ");
scanf("%f", &start);
d = start;
return d;
}
void getIR(float *a)
{
printf("Rate: ");
scanf("%f",a);
}
void getNP(int *years)
{
printf("NumPeriods: ");
scanf("%d", years);
}
float interest(float a,float b,float c)
{
float x;
x = a*b*c;
return x;
}
int main()
{
float pv,ir,fv,Total;
int np;
pv = getPV(); //Amount in account
getIR(&ir); // APR
getNP(&np); // Number of years
fv = interest(pv,ir,np);
Total=fv + pv;
printf("Starting: %.2f\n", pv);
printf(" Ending: %.2f\n", Total);
return 0;
}
**请**编辑您的问题,使其可读性。请参阅:http://stackoverflow.com/editing-help –
你想要简单还是复合兴趣?还可以将问题的字体缩小为更易于管理的大小。最好是默认大小。 –
不知道你需要什么帮助。是的,你需要一个循环,除非你要把[pow()'](http://en.cppreference.com/w/c/numeric/math/pow)函数除掉。在线上的任何一百万个地方都可以为您提供复利的公式,然后您可以将它转换为循环或函数调用。 – WhozCraig