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

TOP

返回列表