返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int price[]={300,250,150,600,1000};
  7.     int p,q,sum=0;
  8.     cout<<"書店"<<endl<<endl;
  9.     cout<<"[商品價目表]"<<endl;
  10.     cout<<"(1)小說\t\t300元"<<endl;
  11.     cout<<"(2)漫畫\t\t250元"<<endl;
  12.     cout<<"(3)雜誌\t\t150元"<<endl;
  13.     cout<<"(4)字典\t\t600元"<<endl;
  14.     cout<<"(5)百科全書\t1000元"<<endl;
  15.     cout<<"(6)結帳"<<endl<<endl;
  16.     start:
  17.     cout<<"請輸入商品代碼: ";
  18.     cin>>p;
  19.     if(p==6)
  20.     {
  21.        goto checkout;
  22.       
  23.     }else if(p>=1 && p<=5)
  24.     {
  25.        cout<<"請輸入數量: ";
  26.        cin>>q;
  27.        if(q>0)
  28.     {  
  29.        sum=sum+price[p-1]*q;
  30.        goto start;
  31.     }else
  32.     {
  33.        cout<<"輸入錯誤"<<endl;
  34.        goto start;
  35.     }
  36.     }else
  37.     {
  38.        cout<<"輸入錯誤"<<endl;
  39.        goto start;
  40.     }
  41.     checkout:
  42.     cout<<endl<<"總共"<<sum<<"元"<<endl;
  43.     system ("pause");
  44.     return 0;
  45. }
複製代碼

TOP

返回列表