/* Problem 4--Making Money
   A very easy problem.  The only sticky point was avoiding round-off
   error. */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main (int argc, char **argv);

int main (int argc, char **argv) {

  int cents, cs, t, C;
  FILE *in, *out;
  double P, I, tc;

 in = fopen ("prob4.in","r");
 out = fopen ("prob4.out","w");
 for (cs=1;fscanf (in,"%lf %lf %d",&P,&I,&C),P>0 || I>0 || C>0;cs++) {
  cents = (int)(P*100+0.5); /* We will work in integers to prevent */
  for (t=0;t<C;t++) { /* round-off error */
   tc = cents * (1+I/(100*C));
   if (fabs (tc - (int)(tc+0.5)) < 1e-5) /*Again check for round-off*/
    cents = (int)(tc+0.5);                /* error */
   else cents = (int) tc;
  }
  fprintf (out,
   "Case %d. $%.2f at %.2f%% APR compounded %d times yields $%.2f\n",
   cs,P,I,C,cents/100.0);
 }
 fclose (in);
 fclose (out);
 return EXIT_SUCCESS;
}
