/* * The main program of our interest rate program and the two functions * it uses for writing the prompt and the headings. * * It also uses another function to print the balances, but that * function is defined in another source file. */ #include #include int main() { void writePrompt(void); void printHeadings(double intrate, double balance, int period); void printBalances(double intrate, double balance, int period); int period; /* length of period */ double balance; /* balance at end of year */ double intrate; /* interest rate */ int n; /* number of values read */ writePrompt(); while ((n = scanf("%lf %lf %i", &intrate, &balance, &period)) == 3) { printHeadings(intrate, balance, period); printBalances(intrate, balance, period); writePrompt(); } if (n != EOF) printf("Warning: Encountered error in reading input.\n"); return EXIT_SUCCESS; } /* Prompt the user for all necessary input values */ void writePrompt(void) { printf("Enter interest rate, principal, and period: "); } /* Print the headings that will precede the interest table */ void printHeadings(double intrate, double balance, int period) { printf("Interest Rate: %7.2f%%\n", intrate * 100); printf("Starting Balance: $ %7.2f\n", balance); printf("Period: %7i years\n\n", period); printf("Year Balance\n"); }