返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     allre:
  7.     system("cls");
  8.     int pay,money;
  9.     int p,q,sum=0,option;
  10.     string name[]={"遙控器車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    "};
  11.     int price[]={450,550,325,200,660,150,380};
  12.     int qty[]={0,0,0,0,0,0,0};
  13.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  14.     cout<<"[商品價目表]"<<endl;
  15.     for(int i=0; i<7; i++)
  16.          cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  17.     cout<<"(8)結帳"<<endl<<endl;
  18.     re:
  19.     cout<<"請輸入商品代碼: ";
  20.     cin>>p;
  21.     if(p==8)
  22.         goto checkout;
  23.     else if(p>=1 && p<=7)
  24.     {
  25.         cout<<"數量: ";
  26.         cin>>q;
  27.         if(q<=0)
  28.         {
  29.             cout<<"輸入錯誤!"<<endl;
  30.             goto re;
  31.         }
  32.         sum+=price[p-1]*q;    //sum=sum+price[p-1]*q
  33.         qty[p-1]+=q;
  34.         goto re;
  35.     }else
  36.     {
  37.         cout<<"輸入錯誤!"<<endl;
  38.         goto re;
  39.     }
  40.     checkout:
  41.     cout<<endl<<"[購物清單]"<<endl;
  42.     cout<<"------------------------------"<<endl;
  43.     for(int i=0; i<7; i++)
  44.     {
  45.         if(qty[i]!=0)
  46.             cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
  47.     }     
  48.     cout<<"------------------------------"<<endl;     
  49.     cout<<"總共"<<sum<<"元!"<<endl<<endl;
  50.     re2:
  51.     cout<<"1-正確無誤 2-重新選購  ";
  52.     cin>>option;
  53.     if(option==1)
  54.         goto change;
  55.     else if(option==2)
  56.         goto allre;
  57.     else
  58.     {
  59.         cout<<"輸入錯誤!"<<endl;
  60.         goto re2;
  61.     }
  62.     change:
  63.     cout<<endl<<"請付帳: ";
  64.     cin>>pay;
  65.     money=pay-sum;
  66.     if(money==0)
  67.         cout<<"剛剛好!"<<endl;
  68.     else if(money<0)
  69.     {
  70.         cout<<"您付的錢不夠,還差"<<-money<<"元!"<<endl;
  71.         goto change;
  72.     }
  73.     else
  74.     {
  75.         cout<<endl<<"找您"<<money<<"元!"<<endl;
  76.         if(money>=1000)
  77.         {
  78.             cout<<"一千元鈔票"<<money/1000<<"張"<<endl;
  79.             money%=1000;   //money=money%1000;         
  80.         }
  81.         if(money>=500)
  82.         {
  83.             cout<<"五百元鈔票"<<money/500<<"張"<<endl;
  84.             money%=500;        
  85.         }
  86.         if(money>=100)
  87.         {
  88.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  89.             money%=100;        
  90.         }
  91.         if(money>=50)
  92.         {
  93.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  94.             money%=50;        
  95.         }
  96.         if(money>=10)
  97.         {
  98.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  99.             money%=10;        
  100.         }
  101.         if(money>=5)
  102.         {
  103.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  104.             money%=5;        
  105.         }
  106.         if(money>=1)
  107.             cout<<"一元硬幣"<<money<<"枚"<<endl;   
  108.     }   
  109.     system("pause");   
  110.     return 0;
  111. }
複製代碼

TOP

返回列表