返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     system("cls");
  8.     int x, y, z ,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.     cout<<"[優惠方案] 滿五千享9折優惠!"<<endl<<endl;
  18.     re2:
  19.     cout<<"請輸入商品代碼: ";
  20.     cin>>x;
  21.     if(x==8)
  22.     {
  23.         cout<<endl;
  24.         goto checkout;
  25.     }
  26.     else if(x>=1 && x<=7)
  27.     {
  28.         cout<<"數量: ";
  29.         cin>>y;
  30.         sum+=price[x-1]*y;
  31.         t[x-1]=t[x-1]+y;
  32.         goto re2;
  33.     }
  34.     checkout:
  35.     cout<<"[購物清單]"<<endl;
  36.     cout<<"============================="<<endl;
  37.     for(int i=0; i<7; i++)
  38.     {
  39.         if(t[i]>0)
  40.         cout<<name[i]<<"\t"<<price[i]<<"元"<<" x "<<t[i]<<"個"<<endl;
  41.     }
  42.     cout<<"============================="<<endl;
  43.     cout<<"總共"<<sum<<"元!"<<endl<<endl;
  44.     if(sum>5000)
  45.     {
  46.         z=sum*0.9;
  47.         cout<<"由於消費滿五千, 享9折優惠!"<<endl<<endl;
  48.         cout<<"您只需付"<<z<<"元! 現省"<<sum-z<<"元!"<<endl;
  49.     }
  50.     system("pause");
  51.     goto re;
  52.     return 0;
  53. }
複製代碼

TOP

返回列表