返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5.     string tag[8]={"玩具車         ","玩具飛機","YOYO ",
  6.                    "足球           ","拼圖 ","玩具槍      ",
  7.                    "可愛玩偶","籃球     "};
  8.     int price[8]={2250,2250,1790,990,2500,1900,1500,2200};
  9.     cout<<"\t※※※智能玩具店※※※"<<endl<<endl;
  10.     cout<<"[商品一覽表]"<<endl;
  11.     for(int i=0; i<8; i++){
  12.        cout<<"<"<<i+1<<">"<<tag[i]<<"\t\t"<<price[i]<<"元"<<endl;   
  13.     }
  14.     cout<<"<9>結帳去"<<"\t\t"<<endl<<endl;
  15.     B:
  16.     int qty[]={0,0,0,0,0,0,0,0};
  17.     int num=0,lab,q,c, pay,coin;
  18.     A:                                                         
  19.     cout<<"請輸入商品代碼: ";
  20.     cin>>lab;
  21.     if(lab==9)
  22.       goto checkout;
  23.     else if(lab>=0){
  24.       cout<<"數量: ";
  25.       cin>>q;
  26.       num+=price[lab-1]*q;
  27.       qty[lab-1]+=q;
  28.       goto A;         
  29.     }  
  30.     else{
  31.       cout<<"輸入錯誤"<<endl;      
  32.       goto A;   
  33.     }  
  34.     checkout:
  35.     cout<<endl<<"[購物清單]"<<endl;
  36.     cout<<"----------------------------"<<endl;
  37.     for(int i=0; i<=7; i++){
  38.       if(qty[i]!=0)        
  39.         cout<<tag[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
  40.     }
  41.     cout<<"----------------------------"<<endl;  
  42.     cout<<endl<<"共"<<num<<"元"<<endl<<endl;
  43.     cout<<"1-正確無誤 2-重新選購 ";
  44.     cin>>c;
  45.     if(c==2){
  46.       cout<<endl;
  47.       goto B;
  48.       num=0;
  49.     }
  50.     if(c==1){
  51.        p:
  52.        cout<<endl;
  53.        cout<<"請您付帳: ";
  54.        cin>>pay;
  55.        if(pay<num&&pay>0){
  56.          cout<<"您付的錢不夠,還差"<<num-pay<<"元"<<endl;
  57.          goto p;         
  58.        }
  59.        else if(pay<=0){
  60.          cout<<"奧客,請付錢"<<endl;
  61.          goto p;
  62.        }
  63.        else{
  64.          coin=pay-num;   
  65.          cout<<endl<<"感謝,找您"<<coin<<"元!"<<endl;     
  66.          if(coin>=1000){   
  67.             cout<<"1000元大鈔"<<coin/1000<<"張"<<endl;
  68.             coin%=1000;
  69.          }
  70.          if(coin>=100){   
  71.             cout<<"100元大鈔"<<coin/100<<"張"<<endl;
  72.             coin%=100;
  73.          }
  74.          if(coin>=50){   
  75.             cout<<"50元摳摳"<<coin/50<<"枚"<<endl;
  76.             coin%=50;
  77.          }
  78.          if(coin>=10){   
  79.             cout<<"10元摳摳"<<coin/10<<"枚"<<endl;
  80.             coin%=10;
  81.          }
  82.          if(coin>=5){   
  83.             cout<<"5元摳摳"<<coin/5<<"枚"<<endl;
  84.             coin%=5;
  85.          }
  86.          if(coin>=1){   
  87.             cout<<"1元摳摳"<<coin/1<<"枚"<<endl;
  88.          }
  89.       }
  90.     }   
  91.     cout<<endl<<"再次感謝您使用本系統"<<endl;                                   
  92.     system("pause");   
  93.     return 0;
  94. }
複製代碼

TOP

返回列表