返回列表 發帖
  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,pay,money,sum=0;
  8.   cout<<"***智能玩具店***"<<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;
  17.   cout<<"(8)結帳"<<endl;
  18.   cout<<"$$請選擇你要的商品$$"<<endl;
  19.   start:
  20.   cout<<"請輸入商品代碼: ";
  21.   cin>>p;
  22.   if(p==8)
  23.   {   
  24.       goto checkout;
  25.   }else if(p>=1 && p<=7)
  26.   {
  27.       cout<<"請輸入商品數量: ";  
  28.       cin>>q;
  29.       if(q>0)
  30.       {
  31.          sum=sum+price[p-1]*q;
  32.          goto start;
  33.       }else
  34.       {
  35.           cout<<"輸入錯誤"<<endl;
  36.           goto start;   
  37.       }      
  38.   }
  39.   else
  40.   {
  41.       cout<<"輸入錯誤"<<endl;
  42.       goto start;            
  43.   }
  44.   checkout:
  45.   cout<<endl<<"總共"<<sum<<"元"<<endl;      
  46.   system("pause");
  47.   return 0;
  48. }  
複製代碼

TOP

返回列表