返回列表 發帖
本帖最後由 劉泳鱔 於 2013-7-6 15:19 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int price[]={450,550,325,200,660,150,380};
  7.     int p,q,sum=0;
  8.     cout<<"$$超能商店$$"<<endl;
  9.     cout<<"[商品價格]"<<endl;
  10.     cout<<"(1)屎一斤\t550元"<<endl;
  11.     cout<<"(2)坦克模型\t550元"<<endl;
  12.     cout<<"(3)魔球\t\t325元"<<endl;
  13.     cout<<"(4)藍圖\t\t200元"<<endl;
  14.     cout<<"(5)機關槍\t660元"<<endl;
  15.     cout<<"(6)驚悚玩偶\t150元"<<endl;
  16.     cout<<"(7)保齡球\t\t380元"<<endl;
  17.     cout<<"[使用說明]"<<endl;
  18.     cout<<"依序輸入想購買的商品與數量,如籃球兩顆請輸入'7 2'"<<endl;
  19.     cout<<"選購完畢時輸入'8 8'進入結帳頁"<<endl<<endl;
  20.     start:
  21.     cout<<"在此輸入: ";
  22.     cin>>p;
  23.     if(p==8)
  24.     {
  25.         goto checkout;               
  26.     }
  27.     else if(p>=1 && p<=7 && q>0)
  28.     {
  29.         sum=sum+price[p-1]*q;
  30.         goto start;
  31.     }else if(p==8 && q==8)
  32.     {
  33.         goto checkout;
  34.     }else
  35.     {
  36.         cout<<"輸入錯誤!"<<endl;
  37.         goto start;            
  38.     }
  39.     checkout:
  40.     cout<<endl<<"總共"<<sum<<"元!"<<endl;
  41.     system("pause");
  42.     return 0;   
  43. }
複製代碼

TOP

返回列表