返回列表 發帖

購物系統 (四)

新增購物清單
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[]={"遙控汽車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    "}; //商品名稱
  7.     int price[]={450,550,325,200,660,150,380};  //商品單價
  8.     int qty[]={0,0,0,0,0,0,0};   //銷售量初始值
  9.     int p,q,sum=0;   //商品代碼,數量,總金額
  10.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  11.     cout<<"[商品價目表]"<<endl;
  12.     cout<<"(1)遙控汽車\t450元"<<endl;
  13.     cout<<"(2)飛機模型\t550元"<<endl;
  14.     cout<<"(3)足球\t\t325元"<<endl;
  15.     cout<<"(4)拼圖\t\t200元"<<endl;
  16.     cout<<"(5)玩具槍\t660元"<<endl;
  17.     cout<<"(6)可愛玩偶\t150元"<<endl;
  18.     cout<<"(7)籃球\t\t380元"<<endl;
  19.     cout<<"(8)結帳"<<endl<<endl;
  20.     start:
  21.     cout<<"請輸入商品代碼: ";
  22.     cin>>p;
  23.     if(p==8)
  24.     {
  25.         goto checkout;
  26.     }else if(p>=1 && p<=7)
  27.     {
  28.         cout<<"數量: ";        
  29.         cin>>q;
  30.         if(q>0)
  31.         {
  32.              sum=sum+price[p-1]*q;
  33.              qty[p-1]=q;
  34.              goto start;      
  35.         }else
  36.         {
  37.              cout<<"輸入錯誤!"<<endl;
  38.              goto start;     
  39.         }   
  40.     }else
  41.     {
  42.         cout<<"輸入錯誤!"<<endl;
  43.         goto start;     
  44.     }
  45.     checkout:
  46.     cout<<endl<<"[購物清單]"<<endl;
  47.     cout<<"-----------------------------"<<endl;
  48.     for(int i=0; i<=6; i++)
  49.     {
  50.        if(qty[i]!=0)     
  51.          cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
  52.     }
  53.     cout<<"-----------------------------"<<endl;
  54.     cout<<"\t\t總共"<<sum<<"元!"<<endl;   
  55.     system("pause");
  56.     return 0;
  57. }
複製代碼

本帖最後由 黃崇維 於 2013-7-20 20:32 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      string name[]={"一星級電腦","二星級電腦","三星級電腦","四星級電腦","五星級電腦","六星級電腦","七星級電腦"};
  7.      int price[]={10000,12000,12300,12340,12345,123456,1234567};
  8.      int qty[]={0,0,0,0,0,0,0};
  9.      int p, q, money, pay, sum=0, a;
  10.      cout<<"崇維智能電腦房屋店"<<endl<<endl;
  11.      cout<<"[電腦價目表]"<<endl;
  12.      cout<<"(1)一星級電腦\t10000元"<<endl;
  13.      cout<<"(2)二星級電腦\t12000元"<<endl;
  14.      cout<<"(3)三星級電腦\t12300元"<<endl;
  15.      cout<<"(4)四星級電腦\t12340元"<<endl;
  16.      cout<<"(5)五星級電腦\t12345元"<<endl;
  17.      cout<<"(6)六星級電腦\t123456元"<<endl;
  18.      cout<<"(7)七星級電腦\t1234567元"<<endl;
  19.      cout<<"(8)結帳"<<endl<<endl;
  20.      start:
  21.      cout<<"請輸入商品代碼: ";
  22.      cin>>p;
  23.      if(p==8)
  24.      {
  25.           goto checkout;
  26.      }else if(p>=1 && p<=7)
  27.      {
  28.           cout<<"請輸入數量:";
  29.           cin>>q;
  30.           if(q>0)
  31.           {
  32.              sum=sum+price[p-1]*q;
  33.              qty[p-1]=q;
  34.              goto start;      
  35.         }else
  36.         {
  37.              cout<<"輸入錯誤!"<<endl;
  38.              goto start;     
  39.         }   
  40.      }else
  41.      {
  42.          cout<<"輸入錯誤!"<<endl;
  43.          goto start;     
  44.      }
  45.      checkout:
  46.      cout<<endl<<"[購物清單]"<<endl;
  47.      cout<<"-------------"<<endl;
  48.      for(int i=0; i<=6; i++)
  49.      {
  50.          if(qty[i]!=0)     
  51.             cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
  52.      }
  53.      cout<<"-------------"<<endl;
  54.      cout<<"\t\t總共"<<sum<<"元!"<<endl;
  55.      system("pause");
  56.      return 0;   
  57. }     
複製代碼

TOP

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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[]={"屎一斤  ","坦克模型","魔球     ","藍圖    ","機關槍  ","驚悚玩偶","保齡球  "};
  7.     int price[]={450,550,325,200,660,150,380};
  8.     int qty[]={0,0,0,0,0,0,0};
  9.     int p,q,sum=0;
  10.     cout<<"$超能商店$"<<endl;
  11.     cout<<"[商品價格]"<<endl;
  12.     cout<<"(1)屎一斤\t550元"<<endl;
  13.     cout<<"(2)坦克模型\t550元"<<endl;
  14.     cout<<"(3)魔球\t\t325元"<<endl;
  15.     cout<<"(4)藍圖\t\t200元"<<endl;
  16.     cout<<"(5)機關槍\t660元"<<endl;
  17.     cout<<"(6)驚悚玩偶\t150元"<<endl;
  18.     cout<<"(7)保齡球\t380元"<<endl;
  19.     cout<<"(8)結帳"<<endl<<endl;
  20.     cout<<"[使用說明]"<<endl;
  21.     cout<<"依序輸入想購買的商品與數量,如籃球兩顆請輸入'7 2'"<<endl;
  22.     cout<<"選購完畢時輸入'8 8'進入結帳頁"<<endl<<endl;
  23.     start:
  24.     cout<<"在此輸入: ";
  25.     cin>>p;
  26.     if(p==8)
  27.     {
  28.         goto checkout;               
  29.     }
  30.     else if(p>=1 && p<=7 && q>0)
  31.     {
  32.         sum=sum+price[p-1]*q;
  33.         qty[p-1]=q;
  34.         goto start;
  35.     }else if(p==8 && q==8)
  36.     {
  37.         goto checkout;
  38.     }else
  39.     {
  40.         cout<<"輸入錯誤!"<<endl;
  41.         goto start;            
  42.     }
  43.     checkout:
  44.     cout<<endl<<"[購物清單]"<<endl;
  45.     cout<<"-------------------------------------"<<endl;
  46.     for(int i=0; i<=6; i++)
  47.     {
  48.                     cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
  49.     }         
  50.     if(qty[i]!=0)
  51.     cout<<"-------------------------------------"<<endl;
  52.     cout<<"\t\t總共"<<sum<<"元!"<<endl;
  53.     system("pause");
  54.     return 0;   
  55. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[]={"四人套房        ","兩人套房        ","七人小木屋        ","孤單一人房        ","百人總統房        ","安靈病房        ","太平間地下房        ","跟泳鱔一夜情套房"};
  7.     int qty[]={0,0,0,0,0,0,0,0};
  8.     int price[]={10000,5000,50000,4444,10,1744,55,10000};
  9.     int h, q, pay, money,sum=0;
  10.     cout<<"以諾豪華九星級飯店"<<endl;
  11.     cout<<"[飯店房間價目表]"<<endl;
  12.     cout<<"(1)四人套房\t10000元"<<endl;
  13.     cout<<"(2)兩人套房\t5000元"<<endl;
  14.     cout<<"(3)七人小木屋\t50000元"<<endl;
  15.     cout<<"(4)孤單一人房\t4444元"<<endl;
  16.     cout<<"(5)百人總統房\t10元"<<endl;
  17.     cout<<"(6)安靈病房\t1744元"<<endl;
  18.     cout<<"(7)太平間地下房\t55元"<<endl;
  19.     cout<<"(8)跟泳鱔一夜情套房\t1元"<<endl;
  20.     cout<<"[付費說明]"<<endl;
  21.     cout<<"把要住的房間代號輸入後,再輸入要買幾間"<<endl;
  22.     cout<<"購買完請輸入9前往結帳"<<endl;
  23.     start:
  24.     cout<<"請輸入商品代碼: ";
  25.     cin>>h;
  26.     if(h==9)
  27.     {
  28.     goto checkout;
  29.             }
  30.     else if(h>=1 && h<=8)
  31.     {
  32.          cout<<"請輸入購買數量: ";
  33.          cin>>q;
  34.             if(q>0)
  35.             {
  36.               sum=sum+price[h-1]*q;
  37.               qty[h-1]=q;
  38.               goto start;
  39.             }
  40.     else
  41.         {
  42.              cout<<"輸入錯誤!"<<endl;
  43.              goto start;     
  44.         }      
  45.     }        
  46.     else
  47.     {
  48.         cout<<"什麼年紀了還會輸入錯誤!!"<<endl;
  49.         goto start;
  50.         }
  51.     checkout:
  52.     cout<<"購物清單"<<endl;
  53.     cout<<"$$$$$$$$$$$$$$$$$$$$"<<endl;  
  54.     for(int i=0;i<=7;i++)
  55.     {
  56.           if(qty[i]!=0)  
  57.           cout<<name[i]<<"\t"<<price[i]<<"元 *"<<qty[i]<<"個"<<endl;
  58.             }
  59.     cout<<"$$$$$$$$$$$$$$$$$$$$"<<endl;
  60.     cout<<"\t\t總共是"<<sum<<"元"<<endl;
  61.     cout<<"請輸入客人付了多少錢: ";
  62.     cin>>pay;
  63.     money=pay-sum;
  64.     if(money==0)
  65.     {
  66.         cout<<"錢剛剛好! 請慢走!"<<endl;
  67.     }
  68.     if(money<0)
  69.     {
  70.         cout<<"錢不夠! 還少"<<-money<<endl;                  
  71.     }
  72.     if(money>0)
  73.     {
  74.          cout<<"總共需要找客人"<<money<<"元";   
  75.          if(money>=500)
  76.          {
  77.             cout<<"500元鈔票"<<money/500<<"張"<<endl;
  78.             money=money%500;
  79.          }
  80.          if(money>=100)
  81.          {
  82.             cout<<"100元鈔票"<<money/100<<"張"<<endl;
  83.             money=money%100;
  84.          }
  85.          if(money>=50)
  86.          {
  87.             cout<<"50元硬幣"<<money/50<<"枚"<<endl;
  88.             money=money%50;
  89.          }
  90.          if(money>=10)
  91.          {
  92.             cout<<"10元硬幣"<<money/10<<"枚"<<endl;
  93.             money=money%10;
  94.          }
  95.     }     
  96. system("pause");
  97. return 0;
  98. }     
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name []={"小說", "漫畫", "雜誌", "字典", "百科全書",};
  7.     int price[]={300,250,150,600,1000};
  8.     int qty[]={0,0,0,0,0};
  9.     int p,q,sum=0;
  10.     cout<<"書店"<<endl<<endl;
  11.     cout<<"[商品價目表]"<<endl;
  12.     cout<<"(1)小說\t\t300元"<<endl;
  13.     cout<<"(2)漫畫\t\t250元"<<endl;
  14.     cout<<"(3)雜誌\t\t150元"<<endl;
  15.     cout<<"(4)字典\t\t600元"<<endl;
  16.     cout<<"(5)百科全書\t1000元"<<endl;
  17.     cout<<"(6)結帳"<<endl<<endl;
  18.     start:
  19.     cout<<"請輸入商品代碼: ";
  20.     cin>>p;
  21.     if(p==6)
  22.     {
  23.        goto checkout;
  24.       
  25.     }else if(p>=1 && p<=5)
  26.     {
  27.        cout<<"請輸入數量: ";
  28.        cin>>q;
  29.        if(q>0)
  30.     {  
  31.        sum=sum+price[p-1]*q;
  32.        qty[p-1]=q;
  33.        goto start;
  34.     }else
  35.     {
  36.        cout<<"輸入錯誤"<<endl;
  37.        goto start;
  38.     }
  39.     }else
  40.     {
  41.        cout<<"輸入錯誤"<<endl;
  42.        goto start;
  43.     }
  44.     checkout:
  45.     cout<<endl<<"[購物清單]"<<endl;
  46.     cout<<"-----------------------"<<endl;
  47.     for(int i=0; i<=4; i++)
  48.     {
  49.        if(qty[i]!=0)
  50.        cout<<name[i]<<"\t"<<price[i]<<"元*"<<qty[i]<<"個"<<endl;
  51.     }
  52.     cout<<"-----------------------"<<endl;
  53.     cout<<endl<<"總共"<<sum<<"元"<<endl;
  54.     system ("pause");
  55.     return 0;
  56. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[]={"遙控汽車","飛機模型","足球","拼圖","玩具槍","可愛玩偶","籃球"};
  7.     int price[]={450,550,325,200,660,150,380};
  8.     int qty[]={0,0,0,0,0,0,0};
  9.     int p,q,sum=0;
  10.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  11.     cout<<"[商品價目表]"<<endl;
  12.     cout<<"(1)遙控汽車\t450元"<<endl;
  13.     cout<<"(2)飛機模型\t550元"<<endl;
  14.     cout<<"(3)足球\t\t325元"<<endl;
  15.     cout<<"(4)拼圖\t\t200元"<<endl;
  16.     cout<<"(5)玩具槍\t660元"<<endl;
  17.     cout<<"(6)可愛玩偶\t150元"<<endl;
  18.     cout<<"(7)籃球\t\t380元"<<endl;
  19.     cout<<"(8)結帳"<<endl<<endl;
  20.     start:
  21.     cout<<"請輸入商品代碼: ";
  22.     cin>>p;
  23.     if(p==8)
  24.     {
  25.         goto checkout;
  26.     }else if(p>=1 && p<=7)
  27.     {
  28.         cout<<"數量: ";        
  29.         cin>>q;
  30.         if(q>0)
  31.         {
  32.              sum=sum+price[p-1]*q;
  33.              goto start;      
  34.         }else
  35.         {
  36.              cout<<"輸入錯誤!"<<endl;
  37.              goto start;     
  38.         }   
  39.     }else
  40.     {
  41.         cout<<"輸入錯誤!"<<endl;
  42.         goto start;     
  43.     }
  44.     checkout:
  45.     cout<<endl<<"{垢物親單}"<<endl;
  46.     cout<<"---------------------------------"<<endl;
  47.     for(int i=0; i<=6; i++)
  48.     {
  49.         if(qty[i]!=0)   
  50.           cout<<name[i]<<"\t"<<price[i]<<"元 *"<<qty[i]<<"個"<<endl;                                            
  51.     }
  52.     cout<<"---------------------------------"<<endl;
  53.     cout<<"\t\t總共"<<sum<<"元"<<endl;
  54.     system("pause");
  55.     return 0;
  56. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[]={"空氣","石油","行星","水","陽光","黃金","泥土"};
  7.     int qty[]={0,0,0,0,0,0,0};
  8.     int price[]={450,550,1000,200,660,150,380};
  9.     int p,q,sum=0;
  10.     cout<<"☆★☆21世紀ㄟ店☆★☆"<<endl<<endl;
  11.     cout<<"[商品價目表]"<<endl;
  12.     cout<<"(1)空氣\t450元"<<endl;
  13.     cout<<"(2)石油\t550元"<<endl;
  14.     cout<<"(3)行星\t1000元"<<endl;
  15.     cout<<"(4)水\t200元"<<endl;
  16.     cout<<"(5)陽光\t660元"<<endl;
  17.     cout<<"(6)黃金\t10000元"<<endl;
  18.     cout<<"(7)泥土\t380元"<<endl;
  19.     cout<<"(8)結帳"<<endl<<endl;
  20.     start:
  21.     cout<<"請輸入商品代碼: ";
  22.     cin>>p;
  23.     if(p==8)
  24.     {
  25.         goto checkout;
  26.     }else if(p>=1 && p<=7)
  27.     {
  28.         cout<<"數量: ";        
  29.         cin>>q;
  30.         if(q>0)
  31.         {
  32.              sum=sum+price[p-1]*q;
  33.              qty[p-1]=q;
  34.              goto start;      
  35.         }else
  36.         {
  37.              cout<<"輸入錯誤!"<<endl;
  38.              goto start;     
  39.         }   
  40.     }else
  41.     {
  42.         cout<<"輸入錯誤!"<<endl;
  43.         goto start;     
  44.     }
  45.     checkout:
  46.     cout<<endl<<"[購物清單]"<<endl;
  47.     cout<<"------------------"<<endl;
  48.     for(int i=0; i<=6; i++)
  49.     {
  50.             if(qty[i]!=0)
  51.             cout<<name[i]<<"\t"<<price[i]<<"元*"<<qty[i]<<"個"<<endl;      
  52.     }  
  53.     cout<<endl<<"總共"<<sum<<"元!"<<endl;
  54.     cout<<"------------------"<<endl;
  55. system("pause");
  56.     return 0;
  57. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     string name[]={"一日喪命散  ","含笑半步癲  ","地獄一日遊  ","地獄拔舌體驗卷","爬劍山體驗卷 ","棺材訂做   "};
  7.     int qty[]={0,0,0,0,0,0};     
  8.     int price[]={1240,136,2584,251,987,654};
  9.     int a,b,sum=0,pay,money;
  10.     cout<<"***歡樂屋***"<<endl;
  11.     cout<<"商品價目表"<<endl;
  12.     cout<<"(1)一日喪命散\t\t1240元"<<endl;
  13.     cout<<"(2)含笑半步癲\t\t136元"<<endl;
  14.     cout<<"(3)地獄一日遊\t\t2584元"<<endl;
  15.     cout<<"(4)地獄拔舌體驗卷\t251元"<<endl;
  16.     cout<<"(5)爬劍山體驗卷\t\t987元"<<endl;
  17.     cout<<"(6)棺材訂做\t\t654元"<<endl;
  18.     cout<<"死亡一概不負責,消費滿5000送棺材乙個!!(限量  鍍金市價10000元)"<<endl;
  19.     cout<<"選購完時代號都輸入8即可進入結帳頁"<<endl;
  20.     start:
  21.     cout<<"請輸入商品代號:"<<endl;
  22.     cin>>a;
  23.     if(a==8)
  24.     {
  25.          goto end;        
  26.     }
  27.     cout<<"請輸入數量:"<<endl;
  28.     cin>>b;
  29.     if(a>=1 && a<=7 && b>0)
  30.     {   
  31.          sum=sum+price[a-1]*b;
  32.          qty[a-1]=b;
  33.          goto start;        
  34.     }else
  35.     {
  36.          cout<<"輸入錯誤"<<endl;
  37.          goto start;      
  38.     }
  39.     end:
  40.     cout<<endl<<"[購物清單]"<<endl;   
  41.     cout<<"-------------------------------"<<endl;
  42.     for(int i=0;i<=5;i++)
  43.     {   
  44.          if(qty[i]!=0)
  45.          {
  46.                       cout<<name[i]<<"\t"<<price[i]<<"*"<<qty[i]<<"個"<<endl;         
  47.          }                    
  48.     }
  49.     cout<<"-------------------------------"<<endl;     
  50.     cout<<endl<<"\t\t總共"<<sum<<"元!"<<endl;
  51.     if(sum>=5000)
  52.     {
  53.          cout<<"由於消費滿5000,贈送鍍金棺材乙個!!"<<endl;
  54.     }
  55.     cout<<"請輸入付了多少錢: ";
  56.     cin>>pay;
  57.     money=pay-sum;
  58.     if(money==0)
  59.     {
  60.         cout<<"錢剛剛好! 請慢走!"<<endl;
  61.     }
  62.     if(money<0)
  63.     {
  64.         cout<<"錢不夠! 還欠"<<-money<<endl;                  
  65.     }
  66.     if(money>0)
  67.     {
  68.          cout<<"總共需要找客人"<<money<<"元";   
  69.          if(money>=500)
  70.          {
  71.             cout<<"500元鈔票"<<money/500<<"張"<<endl;
  72.             money=money%500;
  73.          }
  74.          if(money>=100)
  75.          {
  76.             cout<<"100元鈔票"<<money/100<<"張"<<endl;
  77.             money=money%100;
  78.          }
  79.          if(money>=50)
  80.          {
  81.             cout<<"50元硬幣"<<money/50<<"枚"<<endl;
  82.             money=money%50;
  83.          }
  84.          if(money>=10)
  85.          {
  86.             cout<<"10元硬幣"<<money/10<<"枚"<<endl;
  87.             money=money%10;
  88.          }
  89.          if(money>=5)
  90.          {
  91.             cout<<"5元硬幣"<<money/5<<"枚"<<endl;
  92.             money=money%5;
  93.          }
  94.          if(money>=1)
  95.          {
  96.             cout<<"1元硬幣"<<money/1<<"枚"<<endl;
  97.             money=money%1;
  98.          }
  99.     }
  100.    
  101.      
  102.     system("pause");   
  103.     return 0;   
  104. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.   string name[]={"遙控汽車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    "};
  7.   int price[]={450,550,325,200,660,150,380};
  8.   int qty[]={0,0,0,0,0,0,0};  
  9.   int p,q,pay,money,sum=0;
  10.   cout<<"***智能玩具店***"<<endl;
  11.   cout<<"**商品價目表**"<<endl;
  12.   cout<<"(1)遙控汽車\t450元"<<endl;
  13.   cout<<"(2)飛機模型\t550元"<<endl;
  14.   cout<<"(3)足球\t\t325元"<<endl;
  15.   cout<<"(4)拼圖\t\t200元"<<endl;
  16.   cout<<"(5)玩具槍\t660元"<<endl;
  17.   cout<<"(6)可愛玩偶\t150元"<<endl;
  18.   cout<<"(7)籃球\t\t380元"<<endl;
  19.   cout<<"(8)結帳"<<endl;
  20.   cout<<"$$請選擇你要的商品$$"<<endl;
  21.   start:
  22.   cout<<"請輸入商品代碼: ";
  23.   cin>>p;
  24.   if(p==8)
  25.      goto checkout;
  26.   else
  27.   {
  28.     cout<<"數量: ";
  29.     cin>>q;     
  30.     if(p>=1 && p<=7 && q>0)
  31.     {
  32.         sum=sum+price[p-1]*q;
  33.         qty[p-1]=q;
  34.         goto start;      
  35.     }
  36.     else
  37.     {
  38.         cout<<"輸入錯誤"<<endl;
  39.         goto start;     
  40.     }
  41.   }
  42.      
  43.   checkout:
  44.   cout<<"[購物清單]"<<endl<<endl;
  45.   cout<<"------------------------------"<<endl;
  46.   for(int i=0;i<=6;i++)
  47.   {   
  48.       if(qty[i]!=0)
  49.       cout<<name[i]<<"\t"<<price[i]<<"元 *"<<qty[i]<<"個"<<endl;   
  50.   }
  51.   cout<<"------------------------------"<<endl;
  52.   cout<<"\t\t"<<"總共"<<sum<<"元"<<endl;   
  53.   system("pause");
  54.   return 0;
  55. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[]={"遙控汽車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    "};
  7.     int price[]={450,550,325,200,660,150,380};
  8.     int qty[]={0,0,0,0,0,0,0};
  9.     int p,q,sum=0;
  10.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  11.     cout<<"[商品價目表]"<<endl;
  12.     cout<<"(1)遙控汽車\t450元"<<endl;
  13.     cout<<"(2)飛機模型\t550元"<<endl;
  14.     cout<<"(3)足球\t\t325元"<<endl;
  15.     cout<<"(4)拼圖\t\t200元"<<endl;
  16.     cout<<"(5)玩具槍\t660元"<<endl;
  17.     cout<<"(6)可愛玩偶\t150元"<<endl;
  18.     cout<<"(7)籃球\t\t380元"<<endl;
  19.     cout<<"(8)結帳"<<endl<<endl;
  20.     start:
  21.     cout<<"請輸入商品代碼: ";
  22.     cin>>p;
  23.     if(p==8)
  24.     {
  25.         goto checkout;
  26.     }else if(p>=1 && p<=7)
  27.     {
  28.         cout<<"數量: ";        
  29.         cin>>q;
  30.         if(q>0)
  31.         {
  32.              sum=sum+price[p-1]*q;
  33.              qty[p-1]=q;
  34.              goto start;      
  35.         }else
  36.         {
  37.              cout<<"輸入錯誤!"<<endl;
  38.              goto start;     
  39.         }   
  40.     }else
  41.     {
  42.         cout<<"輸入錯誤!"<<endl;
  43.         goto start;     
  44.     }
  45.     checkout:
  46.     cout<<endl<<"{垢物親單}"<<endl;
  47.     cout<<"---------------------------------"<<endl;
  48.     for(int i=0; i<=6; i++)
  49.     {
  50.         if(qty[i]!=0)   
  51.           cout<<name[i]<<"\t"<<price[i]<<"元 *"<<qty[i]<<"個"<<endl;                                            
  52.     }
  53.     cout<<"---------------------------------"<<endl;
  54.     cout<<"\t\t總共"<<sum<<"元"<<endl;
  55.     system("pause");
  56.     return 0;
  57. }
複製代碼

TOP

返回列表