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

  43. system("pause");
  44. goto re;
  45. return 0;
  46. }
複製代碼

TOP

返回列表