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

TOP

返回列表