返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re2:
  7.     int p,q,sum=0,option,pay,money;
  8.     string name[5]={"CAD     ","黑卡蒂II","冰果    ","超電磁炮    ","贄殿遮那  "};
  9.     int price[5]={40000,245000,200,40000,12500};
  10.     int qty[5]={0,0,0,0,0};
  11.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  12.     cout<<"[商品價目表(一律以日幣計)]"<<endl;
  13.     for(int i=0; i<5; i++)
  14.     {
  15.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  16.     }
  17.     cout<<"(6)結帳"<<endl<<endl;
  18.     cout<<"動漫促銷->滿100元送對老師專用核彈乙枚"<<endl;
  19.     re:
  20.     cout<<"請輸入商品代碼: ";
  21.     cin>>p;
  22.     if(p==6)
  23.         goto checkout;
  24.     else if(p>=1 && p<=5)
  25.     {
  26.         cout<<"數量: ";
  27.         cin>>q;
  28.         if(q<=0)
  29.         {
  30.             cout<<"輸入錯誤!"<<endl;
  31.             goto re;        
  32.         }
  33.         sum+=price[p-1]*q;
  34.         qty[p-1]+=q;         
  35.     }
  36.     else
  37.     {
  38.         cout<<"輸入錯誤!"<<endl;   
  39.     }
  40.     goto re;
  41.     checkout:
  42.     cout<<endl<<"[購物清單]"<<endl;         
  43.     cout<<"-----------------------------"<<endl;
  44.     for(int i=0; i<5; i++)
  45.     {
  46.         if(qty[i]!=0)
  47.             cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;  
  48.     }
  49.     cout<<"-----------------------------"<<endl;         
  50.     cout<<"總共"<<sum<<"元!"<<endl<<endl;
  51.     cout<<"1-正確無誤 2-重新選購  ";
  52.     cin>>option;
  53.     if(option==1)
  54.     {
  55.         goto change;
  56.     }
  57.     else
  58.     {
  59.         system("cls");   
  60.         goto re2;
  61.     }
  62.     change:      
  63.     cout<<endl<<"請付帳: ";
  64.     cin>>pay;
  65.     money=pay-sum;
  66.     if(money==0)
  67.     {
  68.         cout<<"錢剛好!"<<endl<<endl;
  69.     }
  70.     else if(money<0)
  71.     {
  72.         cout<<"錢不夠!還差"<<-money<<"元!"<<endl;
  73.         goto change;     
  74.     }else
  75.     {
  76.         cout<<"找您"<<money<<"元!"<<endl;
  77.         if(money>=1000)
  78.         {
  79.             cout<<"一千元鈔票"<<money/1000<<"張"<<endl;
  80.             money%=1000;
  81.         }
  82.         if(money>=500)
  83.         {
  84.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  85.             money%=500;         
  86.         }
  87.         if(money>=100)
  88.         {
  89.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  90.             money%=100;         
  91.         }
  92.         if(money>=50)
  93.         {
  94.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  95.             money%=50;         
  96.         }
  97.         if(money>=10)
  98.         {
  99.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  100.             money%=10;         
  101.         }
  102.         if(money>=5)
  103.         {
  104.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  105.             money%=5;         
  106.         }
  107.         if(money>0)
  108.         {
  109.             cout<<"一元硬幣"<<money<<"枚"<<endl;
  110.         }
  111.         cout<<endl<<"銘謝惠顧!"<<endl;
  112.         cout<<"滿100元送<對老師專用核彈乙枚>"<<endl;         
  113.     }
  114.     system("pause");
  115.     return 0;   
  116. }
複製代碼
http://fs-old.mis.kuas.edu.tw/~s1102137106/music/

TOP

返回列表