/* balance.c */ /* calculate the balance of a bank account */ /* balance of current year = balance of previous year * (1 + interestrate) */ /* author: Weiwei Chen */ /* date: Oct. 17. 2010 */ /*preprocessor directives*/ #include /*main function*/ int main(void) { /*variable definition*/ double value, previousvalue, interestrate, initialvalue; int years, counter; /*input section*/ printf("Please input the intial amount of money in the account: "); scanf("%lf", &initialvalue); printf("Please input the number of years that the account will be active: "); scanf("%d", &years); printf("Please input the interest rate (in percentage): "); scanf("%lf", &interestrate); /*computation section and output section*/ counter = 1; previousvalue = initialvalue; printf("Year\t\toldbalance\t\tnewbalance\n"); while(counter <= years) { /*computation for the current iteration*/ value = previousvalue * (1 + interestrate / 100); /*output results*/ printf("%d\t\t%10.2f\t\t%10.2f\n", counter, previousvalue, value); /*prepare values for the next iteration*/ previousvalue = value; counter ++; } /*exit*/ return 0; }