1
0

hotel.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* hotel.c -- hotel management functions */
  2. #include <stdio.h>
  3. #include "hotel.h"
  4. int menu(void)
  5. {
  6. int code, status;
  7. printf("\n%s%s\n", STARS, STARS);
  8. printf("Enter the number of the desired hotel:\n");
  9. printf("1) Fairfield Arms 2) Hotel Olympic\n");
  10. printf("3) Chertworthy Plaza 4) The Stockton\n");
  11. printf("5) quit\n");
  12. printf("%s%s\n", STARS, STARS);
  13. while ((status = scanf("%d", &code)) != 1 ||
  14. (code < 1 || code > 5))
  15. {
  16. if (status != 1)
  17. scanf("%*s"); // dispose of non-integer input
  18. printf("Enter an integer from 1 to 5, please.\n");
  19. }
  20. return code;
  21. }
  22. int getnights(void)
  23. {
  24. int nights;
  25. printf("How many nights are needed? ");
  26. while (scanf("%d", &nights) != 1)
  27. {
  28. scanf("%*s"); // dispose of non-integer input
  29. printf("Please enter an integer, such as 2.\n");
  30. }
  31. return nights;
  32. }
  33. void showprice(double rate, int nights)
  34. {
  35. int n;
  36. double total = 0.0;
  37. double factor = 1.0;
  38. for (n = 1; n <= nights; n++, factor *= DISCOUNT)
  39. total += rate * factor;
  40. printf("The total cost will be $%0.2f.\n", total);
  41. }