返回列表 發帖
本帖最後由 黃柏維 於 2013-7-27 14:19 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.   string name[]={"遙控汽車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    "};
  7.   int price[]={450,550,325,200,660,150,380};
  8.   int qty[]={0,0,0,0,0,0,0};  
  9.   int p,q,pay,money,sum=0,a;
  10.   cout<<"***智能玩具店***"<<endl;
  11.   cout<<"**商品價目表**"<<endl;
  12.   cout<<"(1)遙控汽車\t450元"<<endl;
  13.   cout<<"(2)飛機模型\t550元"<<endl;
  14.   cout<<"(3)足球\t\t325元"<<endl;
  15.   cout<<"(4)拼圖\t\t200元"<<endl;
  16.   cout<<"(5)玩具槍\t660元"<<endl;
  17.   cout<<"(6)可愛玩偶\t150元"<<endl;
  18.   cout<<"(7)籃球\t\t380元"<<endl;
  19.   cout<<"(8)結帳"<<endl;
  20.   cout<<"$請選擇你要的商品$"<<endl;
  21.   start:
  22.   cout<<"請輸入商品代碼: ";
  23.   cin>>p;
  24.   if(p==8)
  25.      goto checkout;
  26.   else
  27.   {
  28.     cout<<"數量: ";
  29.     cin>>q;     
  30.     if(p>=1 && p<=7 && q>0)
  31.     {
  32.         sum=sum+price[p-1]*q;
  33.         qty[p-1]=q;
  34.         goto start;      
  35.     }
  36.     else
  37.     {
  38.         cout<<"輸入錯誤"<<endl;
  39.         goto start;     
  40.     }
  41.   }
  42.      
  43.   checkout:
  44.   cout<<"[購物清單]"<<endl<<endl;
  45.   cout<<"------------------------------"<<endl;
  46.   for(int i=0;i<=6;i++)
  47.   {   
  48.       if(qty[i]!=0)
  49.       cout<<name[i]<<"\t"<<price[i]<<"元 *"<<qty[i]<<"個"<<endl;   
  50.   }
  51.   cout<<"------------------------------"<<endl;
  52.   cout<<"\t\t"<<"總共"<<sum<<"元"<<endl;
  53.   cout<<"1-正確無誤 2-重新選購"<<endl;
  54.   cin>> a;
  55.   if(a==1)
  56.   {
  57.   cout<<"請輸入您付的錢: "<<endl;
  58.   cin>>pay;
  59.   cout<<"找您"<<pay-p<<"元"<<endl;
  60.   }
  61.   else if(a==2)
  62.   {
  63.   goto start;
  64.   }
  65.   else
  66.   {
  67.   cout<<"輸入錯誤"<<endl;
  68.   goto start;
  69.   }
  70.   money=pay-sum;
  71.   if(money>=500)

  72.   {
  73.         cout<<"500元鈔票"<<money/500<<"張"<<endl;
  74.         money=money%500;
  75.   }
  76.   if(money>=100)
  77.   {
  78.         cout<<"100元鈔票"<<money/100<<"張"<<endl;
  79.         money=money%100;
  80.   }
  81.   if(money>=50)
  82.   {
  83.         cout<<"50元硬幣"<<money/50<<"枚"<<endl;
  84.         money=money%50;
  85.   }
  86.   if(money>=10)
  87.   {
  88.         cout<<"10元硬幣"<<money/10<<"枚"<<endl;
  89.         money=money%10;
  90.   }
  91.   system("pause");
  92.   return 0;
  93. }   
複製代碼

TOP

返回列表