返回列表 發帖
本帖最後由 洪榜蔓 於 2017-3-4 15:11 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     re:
  7.     system("cls");
  8.     int p,q,sum=0;         
  9.     string name[]={"iPhone1","iPhone2","iPhone3","iPhone4","iPhone5","iPhone6","iPhone7"};
  10.     int price[]={19999,29999,30000,32000,34000,38000,40000};
  11.     cout<<"#iPhone專賣店#"<<endl<<endl;
  12.     cout<<"[商品價目表]"<<endl;
  13.     for(int i=0; i<7; i++)
  14.     {
  15.             cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  16.     cout<<"(8)結帳"<<endl<<endl;
  17.     re2:
  18.     cout<<"請輸入商品代碼: ";
  19.     cin>>p;
  20.     if(p==8)
  21.     {
  22.         goto checkout;  
  23.     }else if(p>=1 && p<=7)  
  24.     {
  25.        cout<<"數量: ";   
  26.        cin>>q;   
  27.        sum+=price[p-1]*q   
  28.        goto re2;   
  29.     }else
  30.     {
  31.          goto re;     
  32.     }
  33.     checkout:
  34.     cout<<endl<<"總共"<<sum<<"元~"<<endl;
  35.     system("pause");
  36.     return 0;
  37. }
複製代碼

TOP

返回列表