返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[7]={"遙控飛機",
  7.                     "水槍    ",
  8.                     "玩偶    ",
  9.                     "足球    ",
  10.                     "拼圖    ",
  11.                     "籃球    ",
  12.                     "玩具車"};
  13.     int price[7]={50000,6500000,70000,655000,999999,300000,750000,};
  14.     int qty[7]={0,0,0,0,0,0,0};
  15.     int p,q,sum=0;
  16.     cout<<"***貴死人玩具店***"<<endl<<endl;
  17.     cout<<"[商品價目表]"<<endl;
  18.     for(int i=0;i<=6;i++)
  19.     {
  20.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;   
  21.     }
  22.     cout<<"(8)結帳"<<endl;
  23.     re:
  24.     cout<<"請輸入商品代碼:"<<endl;
  25.     cin>>p;
  26.     if(p>=1 && p<=7)
  27.     {   
  28.          cout<<"請輸入數量:"<<endl;
  29.          cin>>q;
  30.          if(q>0)
  31.          {
  32.              sum=sum+price[p-1]*q;
  33.              qty[p-1]+=q;
  34.              goto re;
  35.          }
  36.          else  
  37.          {
  38.              cout<<"輸入錯誤!"<<endl;
  39.              goto re;   
  40.          }
  41.     }
  42.     else if(p==8)
  43.     {
  44.          goto checkout;   
  45.     }
  46.     else
  47.     {
  48.          cout<<"輸入錯誤!"<<endl;
  49.          goto re;
  50.     }
  51.     checkout:
  52.     cout<<"[購物清單]"<<endl;
  53.     cout<<"==========================="<<endl;
  54.     for(int i=0;i<=6;i++)
  55.     {
  56.         if(qty[i]!=0)
  57.             cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元*"<<qty[i]<<"個"<<endl;   
  58.     }
  59.     cout<<"==========================="<<endl;         
  60.     cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
  61.     system("pause");
  62.     return 0;   
  63. }
複製代碼

TOP

返回列表