colddays.c 672 B

12345678910111213141516171819202122232425
  1. // colddays.c -- finds percentage of days below freezing
  2. #include <stdio.h>
  3. int main(void)
  4. {
  5. const int FREEZING = 0;
  6. float temperature;
  7. int cold_days = 0;
  8. int all_days = 0;
  9. printf("Enter the list of daily low temperatures.\n");
  10. printf("Use Celsius, and enter q to quit.\n");
  11. while (scanf("%f", &temperature) == 1)
  12. {
  13. all_days++;
  14. if (temperature < FREEZING)
  15. cold_days++;
  16. }
  17. if (all_days != 0)
  18. printf("%d days total: %.1f%% were below freezing.\n",
  19. all_days, 100.0 * (float) cold_days / all_days);
  20. if (all_days == 0)
  21. printf("No data entered!\n");
  22. return 0;
  23. }