返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     system("cls");
  8.     int p,q,r=0;
  9.     int z=0;
  10.     string a[]={"遙控汽車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    "};
  11.     int b[]={450,550,325,200,660,150,380};
  12.     int c[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  13.     int d[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

  14.     cout<<"智能玩具店"<<endl;
  15.     cout<<endl;
  16.     cout<<"[商品價目表]"<<endl;
  17.     for(int i=0; i<=6; i++)
  18.         cout<<"("<<i+1<<")"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
  19.     cout<<"(8)"<<"結帳"<<endl;
  20.     re2:
  21.     cout<<"請輸入商品代碼:";
  22.     cin>>p;
  23.     if(p==8){

  24.         goto checkout;

  25.     }
  26.     else if(p<=7&&p>=1){

  27.         cout<<"數量: ";
  28.         cin>>q;

  29.         r+=b[p-1]*q;
  30.         c[z]=p;
  31.         d[z]=q;
  32.         z++;
  33.         goto re2;
  34.     }
  35.     else{

  36.         cout<<"輸入錯誤"<<endl;
  37.         goto re2;

  38.     }

  39.     checkout:
  40.     cout<<"[購物清單]"<<endl;
  41.     for(int i=0;i<=z;i++){
  42.     if(z>1){
  43.     cout<<a[c[i]-1]<<"\t\t"<<b[c[i]-1]<<"*"<<d[i]<<"個"<<endl;
  44.         }

  45.     }
  46.     cout<<"===================="<<endl;

  47.     cout<<"總共"<<r<<"元!"<<endl;

  48.     system("pause");
  49.     goto re;
  50.     return 0;
  51. }
複製代碼

TOP

返回列表