posts - 68, comments - 19, trackbacks - 0, articles - 1

          導(dǎo)航

          <2017年7月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          留言簿

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          評論排行榜

          開房小程序 c語言

          Posted on 2017-07-20 23:22 viery 閱讀(194) 評論(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);

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

          //根據(jù)費率/入住天數(shù)計算總費用,并顯示結(jié)果
          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)總統(tǒng)套房","2)豪華海景房" );
          11    printf("\n%-20s %-20s","3)VIP客房","4)標(biāo)準(zhǔn)客房" );
          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("請輸入你要預(yù)定的天數(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    
           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("謝謝,已成功預(yù)定,再見。\n");
          33         break;
          34    }

          35
          36
          37
          38    if(code==5)
          39    printf("退出預(yù)定菜單,再見。\n");
          40    return 0;
          41}

          42
                 
          return nights;
          35
          36}
          showprice(double rate,int nights);

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 资兴市| 施秉县| 新密市| 唐河县| 兰考县| 彭泽县| 南京市| 安新县| 英山县| 陆河县| 玉门市| 峡江县| 瓦房店市| 绥棱县| 莲花县| 万载县| 兴安盟| 华亭县| 瑞昌市| 南涧| 共和县| 萝北县| 安岳县| 界首市| 建德市| 莱阳市| 烟台市| 陇西县| 遵义市| 伽师县| 开阳县| 铁岭市| 古蔺县| 鄢陵县| 辽阳市| 东方市| 安宁市| 桐梓县| 康马县| 顺义区| 永兴县|