返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     system("cls");
  8.     int x, y, z, a, money ,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<<endl;
  43.     cout<<"1-正確無誤 2-重新選購  ";
  44.     cin>>z;
  45.     cout<<endl;
  46.     if(z==2)
  47.     {
  48.         goto re;
  49.     }
  50.     else if(z==1)
  51.     {
  52.         re3:
  53.         cout<<"請付帳: ";
  54.         cin>>a;
  55.         cout<<endl;
  56.         if(a<sum)
  57.         {
  58.         cout<<"您付的錢不夠, 還差"<<sum-a<<"元!"<<endl<<endl;
  59.         goto re3;
  60.         }
  61.         else if(sum<a)
  62.         money=a-sum;
  63.         cout<<"找您"<<money<<"元!"<<endl;

  64.         if(money>=100)
  65.         {
  66.             cout<<"一百元鈔票"<<money/100<<"張"<<endl;
  67.             money%=100;
  68.         }
  69.         if(money>=50)
  70.         {
  71.             cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
  72.             money%=50;
  73.         }
  74.         if(money>=10)
  75.         {
  76.             cout<<"十元硬幣"<<money/10<<"枚"<<endl;
  77.             money%=10;
  78.         }
  79.         if(money>=5)
  80.         {
  81.             cout<<"五元硬幣"<<money/5<<"枚"<<endl;
  82.             money%=5;
  83.         }
  84.         if(money>=1)
  85.         {
  86.             cout<<"一元硬幣"<<money/1<<"枚"<<endl;
  87.             money%=1;
  88.         }
  89.         }
  90.     system("pause");
  91.     goto re;
  92.     return 0;
  93. }
複製代碼

TOP

返回列表