返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name []={"小說", "漫畫", "雜誌", "字典", "百科全書",};
  7.     int price[]={300,250,150,600,1000};
  8.     int qty[]={0,0,0,0,0};
  9.     int p,q,sum=0;
  10.     cout<<"書店"<<endl<<endl;
  11.     cout<<"[商品價目表]"<<endl;
  12.     cout<<"(1)小說\t\t300元"<<endl;
  13.     cout<<"(2)漫畫\t\t250元"<<endl;
  14.     cout<<"(3)雜誌\t\t150元"<<endl;
  15.     cout<<"(4)字典\t\t600元"<<endl;
  16.     cout<<"(5)百科全書\t1000元"<<endl;
  17.     cout<<"(6)結帳"<<endl<<endl;
  18.     start:
  19.     cout<<"請輸入商品代碼: ";
  20.     cin>>p;
  21.     if(p==6)
  22.     {
  23.        goto checkout;
  24.       
  25.     }else if(p>=1 && p<=5)
  26.     {
  27.        cout<<"請輸入數量: ";
  28.        cin>>q;
  29.        if(q>0)
  30.     {  
  31.        sum=sum+price[p-1]*q;
  32.        qty[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<=4; i++)
  48.     {
  49.        if(qty[i]!=0)
  50.        cout<<name[i]<<"\t"<<price[i]<<"元*"<<qty[i]<<"個"<<endl;
  51.     }
  52.     cout<<"-----------------------"<<endl;
  53.     cout<<endl<<"總共"<<sum<<"元"<<endl;
  54.     system ("pause");
  55.     return 0;
  56. }
複製代碼

TOP

返回列表