返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.   int n,c,sum=0;
  7.   cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  8.   cout<<"[商品價目表]"<<endl;
  9.   string t[7]={"遙控器車",
  10.                "飛機模型",
  11.                "足球    ",
  12.                "拼圖    ",
  13.                "玩具槍  ",
  14.                "可愛玩偶",
  15.                "籃球    "};
  16.   int p[7]={450,550,325,200,660,150,380};
  17.   for(int i=0;i<7;i++)
  18.   {
  19.        cout<<"("<<i+1<<")"<<t[i]<<"\t"<<p[i]<<"元"<<endl;
  20.   }
  21.   cout<<"(8)結帳"<<endl<<endl;
  22.   n:
  23.   cout<<"請輸入商品代碼:";
  24.   cin>>n;
  25.   if(n>=1 && n<=7)
  26.   {
  27.       c:
  28.       cout<<"數量:";
  29.       cin>>c;
  30.       if(c>0)
  31.       {
  32.            sum=sum+p[n-1]*c;
  33.            goto n;      
  34.       }else
  35.       {
  36.            cout<<"您輸入的數量錯誤"<<endl;
  37.            goto c;     
  38.       }         
  39.   }else if(n==8)
  40.   {
  41.        goto checkout;
  42.   }else
  43.   {
  44.        cout<<"您輸入的商品代碼錯誤"<<endl;
  45.        goto n;
  46.   }
  47.   checkout:
  48.        cout<<endl;   
  49.        cout<<"總共"<<sum<<"元"<<endl;
  50.   system("pause");
  51.   return 0;
  52. }
複製代碼

TOP

返回列表