返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int p,q,sum=0;
  7.     string name[5]={"砍頭優惠卷","特效搖頭丸","自殺體驗卷","被打免費票","舒柔鼻涕蟲",};
  8.     int price[5]={99111,458645,14000,99999,100000};
  9.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  10.     cout<<"[商品價目表]"<<endl;
  11.     int qty[5]={0,0,0,0,0};
  12.     for(int i=0; i<5; i++)
  13.     {
  14.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  15.     }
  16.     cout<<"(8)結帳"<<endl<<endl;
  17.     re:
  18.     cout<<"請輸入商品代碼: ";
  19.     cin>>p;
  20.     if(p==8)
  21.         goto checkout;
  22.     else if(p>=1 && p<=7)
  23.     {
  24.         cout<<"數量: ";
  25.         cin>>q;
  26.         if(q<=0)
  27.         {
  28.             cout<<"輸入錯誤!"<<endl;
  29.             goto re;        
  30.         }
  31.         sum+=price[p-1]*q;
  32.         qty[p-1]+=q;     
  33.     }
  34.     else
  35.     {
  36.         cout<<"輸入錯誤!"<<endl;   
  37.     }
  38.     goto re;
  39.     checkout:   
  40.     cout<<endl<<"噁心清單"<<endl;
  41.     cout<<"----------------------------------"<<endl;
  42.     for (int i=0;i<5;i++)
  43.     {
  44.         if(qty[i]!=0)
  45.             cout<<name[i]<<"\t"<<price[i]<<"元  *  "<<qty[i]<<"個"<<endl;        
  46.     }   
  47.     cout<<"----------------------------------"<<endl;
  48.     cout<<"總共"<<sum<<"元!"<<endl<<endl;   
  49.     system("pause");
  50.     return 0;   
  51. }
複製代碼

TOP

返回列表