返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     int sum=0;
  8.     int code,qty,option,money,pay;
  9.     string name[]={"齊爾 爆焰龍捲","卡莉 聖域福音","悟空 合金進化","夜叉 戰地之王","瑟斐斯 煉獄修羅","柯里納卡 荒漠邪翅","馬洛斯 鋼鐵戰線"};
  10.     int price[]={15,20,24,18,30,12,60,2000};
  11.     int count[]={0,0,0,0,0,0,0};   
  12.     cout<<"☆★☆傳說對決造型專賣店☆★☆"<<endl<<endl;
  13.     cout<<"[商品價目表]"<<endl;
  14.     for(int i=0;i<7;i++)
  15.     {
  16.     cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  17.     }
  18.     cout<<"(8)結帳"<<endl<<endl;
  19.     while(true)
  20.     {
  21.         cout<<"請輸入商品代碼:";
  22.         cin>>code;
  23.         if(code<1 || code>8)
  24.         {
  25.             cout<<"輸入錯誤!"<<endl;
  26.             continue;
  27.         }
  28.         if(code==8)
  29.         break;
  30.         cout<<"數量:";
  31.         cin>>qty;
  32.         if(qty<1 || qty>999)
  33.         {
  34.             cout<<"輸入錯誤!"<<endl;
  35.             continue;
  36.         }
  37.         count[code-1]+=qty;
  38.         sum+=price[code-1]*qty;               
  39.     }
  40.     cout<<"[購物清單]"<<endl;
  41.     cout<<"------------------------"<<endl;
  42.     for(int j=0;j<7;j++)
  43.     {
  44.         if(count[j]!=0)
  45.         {
  46.         cout<<name[j]<<"\t"<<price[j]<<"元 *"<<count[j]<<"個"<<endl;
  47.         }
  48.     }
  49.     cout<<"------------------------"<<endl;
  50.     cout<<endl<<"總共"<<sum<<"元"<<endl<<endl;
  51.     re2:
  52.     cout<<"1-正確無誤 2-重新選購";
  53.     cin>>option;
  54.     cout<<endl;
  55.     if(option==1)
  56.     {
  57.         re3:         
  58.         cout<<"請付帳";
  59.         cin>>pay;
  60.         money=pay-sum;
  61.         if(money>0)
  62.         {
  63.             cout<<"找您"<<money<<"元!"<<endl;
  64.             if(money>=500)
  65.             {
  66.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  67.             money=money%500;
  68.             }
  69.             if(money>=100)
  70.             {
  71.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  72.             money=money%100;
  73.             }
  74.             if(money>=50)
  75.             {
  76.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  77.             money=money%50;
  78.             }
  79.             if(money>=10)
  80.             {
  81.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  82.             money=money%10;
  83.             }
  84.             if(money>=1)
  85.             {
  86.             cout<<"一元硬幣"<<money/1<<"枚"<<endl;
  87.             }
  88.         }     
  89.         else if(money==0)
  90.         {
  91.             cout<<"銘謝惠顧!"<<endl;
  92.         }else
  93.         {
  94.             cout<<"您付的錢不夠,還差"<<money<<"元"<<endl;
  95.             goto re3;
  96.         }            
  97.     }else if(option==2)
  98.     {
  99.         goto re;
  100.     }else
  101.     {
  102.         cout<<"您輸入的代碼有誤!"<<endl;
  103.         goto re2;
  104.     }
  105.     system("pause");
  106.     return 0;
  107. }

  108.    
複製代碼

TOP

返回列表