重新改进了,但是还是不行。请指点.
#include <stdio.h>
main()
{
double principal, rate, gain;
int i, years;
char yn;
printf("\nPlease input your initial investment:$\n");
scanf("%lf", & principal);
printf("\nPlease input the interest rate you expect:\n");
scanf("%lf", &rate);
rate = rate /100.0;
printf("\nPlease input the number of years you would like to do your investment: ");
scanf("%d", &years);
printf("\nWould you like to calculate your gain? Y/N ");
fflush(stdin);
scanf ("%c", &yn);
while (yn=='Y')
{
for (i=0; i<years; i++)
{
gain=principal*(1.0 + rate);
printf ("\nAt the end of Year %d\tyou will have %20.2lf", i, gain);
}
getchar();
printf( "\n\n\nWould you like continue to calculate your gain? Y/N ");
while ( getchar() != '\n' );
scanf ("%c", &yn);
}
}