1
0

paint.c 537 B

1234567891011121314151617181920
  1. /* paint.c -- uses conditional operator */
  2. #include <stdio.h>
  3. #define COVERAGE 350 // square feet per paint can
  4. int main(void)
  5. {
  6. int sq_feet;
  7. int cans;
  8. printf("Enter number of square feet to be painted:\n");
  9. while (scanf("%d", &sq_feet) == 1)
  10. {
  11. cans = sq_feet / COVERAGE;
  12. cans += ((sq_feet % COVERAGE == 0)) ? 0 : 1;
  13. printf("You need %d %s of paint.\n", cans,
  14. cans == 1 ? "can" : "cans");
  15. printf("Enter next value (q to quit):\n");
  16. }
  17. return 0;
  18. }