我的代码:调试C代码是初学者
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int year;
double capital, rate;
float deposit;
char a, y, n;
printf("Input rate, year, capital:");
printf("Compound interest (Y/N)?");
scanf("%lf,%d,%lf", &capital, &year, &rate);
scanf(" %c", &a);
if (a = 'y')
{
deposit = capital*pow((1 + rate), n);
printf("deposit = %.4f\n");
}
else if (a = 'n')
{
deposit = capital*(1 + rate * n);
printf("deposit = %.4f\n");
}
return 0;
}
我不知道如何处理这样的:
我想计算存款与已知的资本,年和年。 如果我输入y,我将使用存款=资本*(1 +利率)n 如果我输入n,我将使用存款=资本*(1 +利率* n)
if(a ='y')<---将此更改为if(a =='y')。使用double equals来检查是否相等。与(a ='n')相同 –
'printf(“deposit =%.4f \ n”);' - >'printf(“deposit =%.4f \ n”,存款);' – BLUEPIXY
Aside:why '浮存;'而不是'双重存款;'? –