Posted on 2017-07-20 23:22
viery 閱讀(190)
評論(0) 編輯 收藏
#define QUIT 5
#define DROOM 166.00
#define CROOM 266.00
#define BROOM 466.00
#define AROOM 666.00

#define DISCOUNT 0.95
#define STARS "******************************"

//顯示選擇列表
int menu(void);

//返回預定天數
int getnight(void);

//根據費率/入住天數計算總費用,并顯示結果
void
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)總統套房","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("請輸入你要預定的天數:\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
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;
35
36
} showprice(double rate,int nights);