返回列表 發帖
  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.     int t[7]={0};
  9.     string n[7]={"遙控汽車","飛機模型","足球  ","拼圖  ","玩具槍 ","可愛玩偶","籃球  "};
  10.     int p[7]={450,550,325,200,660,150,380};

  11.     cout<<"***智能玩具店***"<<endl;
  12.     cout<<"[價目表]"<<endl;
  13.     for(int i=0;i<7;i++)
  14.         cout<<"("<<i+1<<")"<<n[i]<<"\t"<<p[i]<<"元"<<endl;
  15.     cout<<"(8)結帳"<<endl;
  16. re2:
  17.     cout<<"請輸入商品代號: "<<endl;
  18.     cin>>x;
  19.     if(x==8)
  20.         goto checkout;
  21.     else if(x>=1&&x<=7){
  22.         cout<<"輸入數量"<<endl;
  23.         cin>>y;
  24.         sum+=p[x-1]*y;
  25.         t[x-1]=t[x-1]+y;
  26.         goto re2;
  27.     }
  28.     else
  29.         goto re;
  30.     checkout:
  31.         cout<<"[購物清單]"<<endl;
  32.         cout<<"--------------------------------"<<endl;
  33.         for(int i=0;i<7;i++){
  34.             if(t[i]>0)
  35.             cout<<n[i]<<"\t"<<p[i]<<"元*"<<t[i]<<endl;
  36.         }
  37.         cout<<"--------------------------------"<<endl;
  38.         cout<<"總共"<<sum<<"元"<<endl;
  39.     int option ,money;
  40.     cout<<"1-正確無誤 2-重新選購"<<endl;
  41.     cin>>option;
  42.     switch (option){

  43. case 1:
  44.         cout<<"請付帳"<<endl;
  45.         cin>>money;
  46.         if (money<sum)
  47.             cout<<"金額不足,還差"<<sum-money<<"元"<<endl;
  48.         else if(money==sum)
  49.             cout<<"謝謝惠顧"<<endl;

  50.         else{
  51.         int c=money-sum;
  52.         cout<<"找您"<<c<<"元"<<endl;

  53.             if(c>=500){
  54.                 cout<<c/500<<"張500元鈔票"<<endl;
  55.                 c=c%500;
  56.             }
  57.             if(c>=100){
  58.                 cout<<c/100<<"張100元鈔票"<<endl;
  59.                 c=c%100;
  60.             }
  61.             if(c>=50){
  62.                 cout<<c/50<<"個50元硬幣"<<endl;
  63.                 c=c%50;
  64.             }
  65.             if(c>=10){
  66.                 cout<<c/10<<"個10元硬幣"<<endl;
  67.                 c=c%10;
  68.             }
  69.             if(c>=5){
  70.                 cout<<c/5<<"個5元硬幣"<<endl;
  71.                 c=c%5;
  72.             }
  73.             if(c>0)
  74.                 cout<<c<<"個1元硬幣"<<endl;
  75.         }
  76. case 2:
  77.     break;
  78. default:
  79.     cout<<"輸入錯誤"<<endl;
  80.     break;
  81. }
  82. system("pause");
  83. goto re;
  84. return 0;

  85. }
複製代碼

TOP

  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

返回列表