
















1
#include <stdio.h>
2
#include "hotel.h"
3
4
int menu(void)
5
{
6
int code,status;
7
8
printf("\n%s%s\n",STARS,STARS);
9
printf("請按照提示選擇入住的房間:\n");
10
printf("%-20s %-20s","1)總統(tǒng)套房","2)豪華海景房" );
11
printf("\n%-20s %-20s","3)VIP客房","4)標準客房" );
12
printf("\n%-20s","5)退出菜單");
13
printf("\n%s%s\n",STARS,STARS);
14
15
while((status = scanf("%d",&code)) != 1 || (code <1 || code >5))
16
{
17
if(status !=1)
18
scanf("%*s");
19
printf("請輸入菜單上所顯示的選項 1-5。\n");
20
}
21
return code;
22
}
23
24
int getnight(void)
25
{
26
int nights,status;
27
printf("請輸入你要預定的天數(shù):\n");
28
while((status = scanf("%d",&nights)) != 1 || (nights <1 || nights >1000))
29
{
30
if(status !=1)
31
scanf("%*s");
32
printf("請輸入菜單上所顯示的選項 1-1000。\n");
33
}
34
35
36
}
showprice(double rate,int nights);
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

1
#include <stdio.h>
2
#include "hotel.h"
3
4
int main()
5
{
6
int nights;
7
double rate;
8
int code;
9
10
11
12
while((code=menu())!=QUIT)
13
{
14
switch (code)
15
{
16
case 1:rate=AROOM;
17
break;
18
case 2:rate=BROOM;
19
break;
20
case 3:rate=CROOM;
21
break;
22
case 4:rate=DROOM;
23
break;
24
default:
25
rate=0.0;
26
printf("無折扣!\n");
27
break;
28
}
29
nights=getnight();
30
31
showprice(rate,nights);
32
printf("謝謝,已成功預定,再見。\n");
33
break;
34
}
35
36
37
38
if(code==5)
39
printf("退出預定菜單,再見。\n");
40
return 0;
41
}
42
return nights;
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

35

36
