返回列表 發帖
  1. int p,q,sum=0;
  2.     string name[]={"遙控器車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    "};
  3.     int price[]={450,550,325,200,660,150,380};
  4.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  5.     cout<<"[商品價目表]"<<endl;
  6.     for(int i=0; i<7; i++)
  7.          cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  8.     cout<<"(8)結帳"<<endl<<endl;
  9.     re:
  10.     cout<<"請輸入商品代碼: ";
  11.     cin>>p;
  12.     if(p==8)
  13.         goto checkout;
  14.     else if(p>=1 && p<=7)
  15.     {
  16.         cout<<"數量: ";
  17.         cin>>q;
  18.         if(q<=0)
  19.         {
  20.             cout<<"輸入錯誤!"<<endl;
  21.             goto re;
  22.         }
  23.         sum+=price[p-1]*q;
  24.         goto re;
  25.     }else
  26.     {
  27.         cout<<"輸入錯誤!"<<endl;
  28.         goto re;
  29.     }
  30.     checkout:
  31.         cout<<endl<<"總共"<<sum<<"元!"<<endl;
複製代碼

TOP

返回列表