Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
457 B

  1. #include <stdio.h>
  2. #define DAYS_PER_WEEK 7
  3. unsigned getDays(void);
  4. int main (void) {
  5. int days;
  6. days = getDays();
  7. while (days != 0) {
  8. printf("%d days are %d weeks, %d days\n", days, days / DAYS_PER_WEEK, days % DAYS_PER_WEEK);
  9. days = getDays();
  10. }
  11. return 0;
  12. }
  13. unsigned getDays(void) {
  14. int days;
  15. printf("Number of days (<=0 to quit): ");
  16. if (scanf("%d", &days) != 1 || days <= 0) {
  17. days = 0;
  18. }
  19. return days;
  20. }