返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.   cout<<"***智能玩具店***"<<endl<<endl;
  7.   cout<<"[商品價目表]"<<endl;
  8.   
  9.   string a[5]={"bmw","法拉利","藍寶潔尼  ",
  10.                "賓士  ","奧迪 "};
  11.   int price[5]={400,550,600,250,150,};
  12.   int p,q,sum=0;   
  13.   for(int i=0;i<5;i++)
  14.   {
  15.       cout<<"("<<i+1<<")"<<a[i]<<"\t"<<price[i]<<"萬元"<<endl;
  16.   }  
  17.   cout<<"(6)結帳"<<endl<<endl;
  18.   re:
  19.   cout<<"請輸入商品代碼: ";
  20.   cin>> p;
  21.   if(p>=1 && p<=5)
  22.   {   
  23.      cout<<"數量: ";
  24.      cin>> q;
  25.      if(q>0)  
  26.      {      
  27.         sum= sum+ price[p-1]*q;  
  28.         goto re;   
  29.      }
  30.   }else if(p==6)
  31.    {
  32.       goto checkout;
  33.    }
  34.    else
  35.    {
  36.        cout<<"error"<<endl;          
  37.            goto re;
  38.         }
  39.   checkout:
  40.   cout<<"總金額: "<<sum<<"萬元"<<endl;
  41.   system("pause");
  42.   return 0;
  43. }
複製代碼

TOP

返回列表