返回列表 發帖
本帖最後由 洪振庭 於 2015-3-22 11:43 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int p,q,sum=0;
  7.     string name[7]={"速效跳課糖","米你毛毛球","無頭帽","金斯雀奶油","攜帶型沼澤","假魔杖","伸縮耳"};
  8.     int price[7]={90,150,74,3,80,1,4};
  9.     int qty[7]={0,0,0,0,0,0,0};
  10.     cout<<"****衛氏巫師法寶店****"<<endl;
  11.     cout<<"<=商品價目表=>"<<endl;
  12.     for(int i=0; i<7; 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<7; i++)
  43.     {
  44.         if(qty[i]!=0)
  45.             cout<<name[i]<<"\t"<<price[i]<<"加隆 * "<<qty[i]<<"個"<<endl;  
  46.     }
  47.    
  48.     system("pause");
  49.     return 0;   

  50. }
複製代碼

TOP

返回列表