Posted on 2017-07-20 23:22
viery 阅读(186)
评论(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
4int 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
24int 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
4int 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);