返回列表 發帖
  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<<endl;
  11.     cout<<"[商品價目表]"<<endl;
  12.     cout<<"(1)遙控汽車\t450元"<<endl;
  13.     cout<<"(2)飛機模型\t550元"<<endl;
  14.     cout<<"(3)足球\t\t325元"<<endl;
  15.     cout<<"(4)遙控飛機\t200元"<<endl;
  16.     cout<<"(5)玩具槍\t660元"<<endl;
  17.     cout<<"(6)可愛玩偶\t150元"<<endl;
  18.     cout<<"(7)籃球\t\t380元"<<endl<<endl;
  19.     cout<<"(8)結帳"<<endl<<endl;
  20.     start:
  21.     cout<<"請輸入商品代碼: ";
  22.     cin>>p;
  23.     if(p==8)
  24.     {
  25.         goto checkout;
  26.     }else if(p>=1 && p<=7)
  27.     {
  28.         cout<<"數量: ";        
  29.         cin>>q;
  30.         if(q>0)
  31.         {
  32.              sum=sum+price[p-1]*q;
  33.              goto start;      
  34.         }else
  35.         {
  36.              cout<<"輸入錯誤!"<<endl;
  37.              goto start;     
  38.         }   
  39.     }else
  40.     {
  41.         cout<<"輸入錯誤!"<<endl;
  42.         goto start;     
  43.     }
  44.     checkout:
  45.     cout<<endl<<"[購物清單]"<<endl;
  46.     cout<<"----------------------"<<endl;
  47.     for(int i=0; i<=6; i++)         
  48.      {
  49.         if(qty[i]!=0)                                          
  50.       cout<<name[i]<<"\t"<<price[i]<<"元*"<<qty[i]<<"個"<<endl;                                            
  51.      }
  52.     cout<<"----------------------"<<endl;
  53.     cout<<endl<<"/t/t總共"<<sum<<"元"<<endl;   
  54.     system("pause");
  55.     return 0;
  56. }
複製代碼

TOP

返回列表