更新时间2018-11-01 21:07:25
#include<stdio.h>
#include<math.h>
int main()
{
int n;
double C,R,D,F,G;
char a;
printf("Input rate, year, capital:");
scanf("%lf,%d,%lf",&R,&n,&C);
printf("Compound interest (Y/N)?");
scanf(" %c",&a);
if ('a=y')
{
F=C*pow((1+R),n);
G = F;
}
else
{
D=C*(1+R*n);
G = D;
}
printf("deposit = %.4f ",G);
}
你的程序中:字符比较有错:if ('a=y');另外把两个scanf合为一次输入。改后的程序如下:
#include<stdio.h>
#include<math.h>
int main()
{
int n;
double C,R,D,F,G;
char a;
printf("Input rate, year, capital,Compound interest (y/n):");
scanf("%lf,%d,%lf,%c",&R,&n,&C,&a);
if (a=='y')
{
F=C*pow((1+R),n);
G = F;
}
else
{
D=C*(1+R*n);
G = D;
}
printf("deposit = %.4f
",G);
}
程序的两种运行结果: