/* Problem 8--Making A Budget This wasn't too bad. This solution just chugs through the data. Note that "cost" begins with a lowercase "c" in this program. There was a typo in the problem description. */ #include #include int main (int argc, char **argv); int min (int a, int b); int max (int a, int b); int main (int argc, char **argv) { FILE *in, *out; int m, hire, sal, sev, T[24], i, k, cs, cost, emp, nemp, keep; in = fopen ("prob8.in","r"); out = fopen ("prob8.out","w"); for (cs=1;fscanf (in,"%d",&m),m>0;cs++) {/* read # of months */ fscanf (in,"%d %d %d",&hire, &sal, &sev); /* get payment stuff */ for (i=0;i nemp) cost += (emp-nemp)*sev; else if (nemp > emp) cost += (nemp-emp)*hire; cost += nemp*sal; /* Pay the employees */ emp = nemp; } fprintf (out,"Case %d, cost = $%d\n",cs,cost); } fclose (in); fclose (out); return EXIT_SUCCESS; } /* Computes the minimum of two integers. */ int min (int a, int b) { return a < b ? a : b; } /* Computes the maximum of two integers. */ int max (int a, int b) { return a > b ? a : b; }