返回列表 發帖
本帖最後由 蘇昱安 於 2013-7-6 15:50 編輯
  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<<endl;
  9.     cout<<"[商品價目表]"<<endl;
  10.     cout<<"(1)遙控汽車\t450元"<<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<<endl;
  17.     cout<<"(8)結帳"<<endl<<endl;
  18.     start:
  19.     cout<<"請輸入商品代碼: ";
  20.     cin>>p;
  21.     if(p==8)
  22.     {
  23.         goto checkout;
  24.     }else if(p>=1 && p<=7)
  25.     {
  26.         cout<<"數量: ";        
  27.         cin>>q;
  28.         if(q>0)
  29.         {
  30.              sum=sum+price[p-1]*q;
  31.              goto start;      
  32.         }else
  33.         {
  34.              cout<<"輸入錯誤!"<<endl;
  35.              goto start;     
  36.         }   
  37.     }else
  38.     {
  39.         cout<<"輸入錯誤!"<<endl;
  40.         goto start;     
  41.     }
  42.     checkout:
  43.     cout<<endl<<"總共"<<sum<<"元"<<endl;   
  44.     system("pause");
  45.     return 0;
  46. }
複製代碼

TOP

返回列表