返回列表 發帖
  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,sum=0;
  10.     cout<<"$超能商店$"<<endl;
  11.     cout<<"[商品價格]"<<endl;
  12.     cout<<"(1)屎一斤\t550元"<<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)保齡球\t380元"<<endl;
  19.     cout<<"(8)結帳"<<endl<<endl;
  20.     cout<<"[使用說明]"<<endl;
  21.     cout<<"依序輸入想購買的商品與數量,如籃球兩顆請輸入'7 2'"<<endl;
  22.     cout<<"選購完畢時輸入'8 8'進入結帳頁"<<endl<<endl;
  23.     start:
  24.     cout<<"在此輸入: ";
  25.     cin>>p;
  26.     if(p==8)
  27.     {
  28.         goto checkout;               
  29.     }
  30.     else if(p>=1 && p<=7 && q>0)
  31.     {
  32.         sum=sum+price[p-1]*q;
  33.         qty[p-1]=q;
  34.         goto start;
  35.     }else if(p==8 && q==8)
  36.     {
  37.         goto checkout;
  38.     }else
  39.     {
  40.         cout<<"輸入錯誤!"<<endl;
  41.         goto start;            
  42.     }
  43.     checkout:
  44.     cout<<endl<<"[購物清單]"<<endl;
  45.     cout<<"-------------------------------------"<<endl;
  46.     for(int i=0; i<=6; i++)
  47.     {
  48.                     cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
  49.     }         
  50.     if(qty[i]!=0)
  51.     cout<<"-------------------------------------"<<endl;
  52.     cout<<"\t\t總共"<<sum<<"元!"<<endl;
  53.     system("pause");
  54.     return 0;   
  55. }
複製代碼

TOP

返回列表