返回列表 發帖

購物系統 (二)

本帖最後由 tonyh 於 2014-2-8 18:08 編輯

新增 "請輸入商品代碼:" 與 "數量:" 的選項,
並於結帳時計算出總共多少錢, 執行畫面如下圖所示.

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[7]={"遙控汽車","飛機模型","足球  ","拼圖  ",
  7.                     "玩具槍","可愛玩偶","籃球  "};  //商品名稱
  8.     int price[7]={450,550,325,200,660,150,380};     //商品單價
  9.     int p,q,sum=0;      //商品代碼,數量,總金額
  10.     cout<<"☆★☆ 智能玩具店 ☆★☆"<<endl<<endl;
  11.     cout<<"[商品價目表]"<<endl;
  12.     for(int i=0; i<=6; i++)
  13.     {
  14.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;     
  15.     }
  16.     cout<<"(8)結帳"<<endl<<endl;
  17.     re:
  18.     cout<<"請輸入商品代碼: ";
  19.     cin>>p;
  20.     if(p>=1 && p<=7)
  21.     {
  22.         cout<<"數量: ";
  23.         cin>>q;
  24.         if(q>0)
  25.         {
  26.             sum=sum+price[p-1]*q;
  27.             goto re;
  28.         }else
  29.         {
  30.             cout<<"輸入錯誤!"<<endl;
  31.             goto re;  
  32.         }
  33.     }else if(p==8)
  34.     {
  35.         goto checkout;      
  36.     }else
  37.     {
  38.         cout<<"輸入錯誤!"<<endl;
  39.         goto re;     
  40.     }
  41.     checkout:
  42.     cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
  43.     system("pause");
  44.     return 0;
  45. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

本帖最後由 張峻瑋 於 2014-2-8 18:16 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[8]={"遙控飛機",
  7.                     "水槍  ",
  8.                     "玩偶  ",
  9.                     "足球  ",
  10.                     "拼圖  ",
  11.                     "籃球  ",
  12.                     "玩具車"};
  13.     int price[8]={50000,6500000,70000,655000,999999,300000,750000,};
  14.     int p,q,sum=0;
  15.     cout<<"***貴死人玩具店***"<<endl<<endl;
  16.     cout<<"[商品價目表]"<<endl;
  17.     for(int i=0;i<=6;i++)
  18.     {
  19.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;   
  20.     }
  21.     cout<<"(8)結帳"<<endl;
  22.     re:
  23.     cout<<"請輸入商品代碼:"<<endl;
  24.     cin>>p;
  25.     if(p>=1 && p<=7)
  26.     {   
  27.          cout<<"請輸入數量:"<<endl;
  28.          cin>>q;
  29.          if(q>0)
  30.          {
  31.              sum=sum+price[p-1]*q;
  32.              goto re;
  33.          }
  34.          else  
  35.          {
  36.              cout<<"輸入錯誤!"<<endl;
  37.              goto re;   
  38.          }
  39.     }
  40.     else if(p==8)
  41.     {
  42.          goto checkout;   
  43.     }
  44.     else
  45.     {
  46.          cout<<"輸入錯誤!"<<endl;
  47.          goto re;
  48.     }
  49.     checkout:
  50.     cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
  51.     system("pause");
  52.     return 0;   
  53. }
複製代碼

TOP

本帖最後由 張郁庭 於 2014-2-15 16:41 編輯
  1. #include<iostream>
  2. #include<iostream>
  3. #include<cstdlib>
  4. using namespace std;
  5. int main()
  6. {
  7.    string name[7]={"冬瓜茶","蘋果冰沙","檸檬愛玉","珍珠奶茶","阿華田","多多綠茶","紅茶"};
  8.    int price[7]={15,30,25,25,25,25,15};
  9.    int p,q,sum=0;
  10.     cout<<"☆★☆ 超級飲料店 ☆★☆"<<endl<<endl;
  11.     cout<<"[商品價目表]"<<endl;
  12.     for(int i=0; i<=6; i++)
  13.     {
  14.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;     
  15.     }
  16.     cout<<"(8)結帳"<<endl<<endl;
  17.     re:
  18.     cout<<"請輸入商品代碼: ";
  19.     cin>>p;
  20.     if(p>=1 && p<=7)
  21.     {
  22.         cout<<"數量: ";
  23.         cin>>q;
  24.         if(q>=0)
  25.         {
  26.             sum=sum+price[p-1]*q;
  27.             goto re;
  28.         }else
  29.         {
  30.             cout<<"輸入錯誤!"<<endl;
  31.             goto re;  
  32.         }
  33.     }else if(p==8)
  34.     {
  35.         goto checkout;      
  36.     }else
  37.     {
  38.         cout<<"輸入錯誤!"<<endl;
  39.         goto re;     
  40.     }
  41.     checkout:
  42.     cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
  43.     system("pause");
  44.     return 0;
  45. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main ()
  5. {
  6.   cout<<"∮∮∮愛心甜點店店∮∮∮"<<endl;
  7.   cout<<"~商品價目表~"<<endl;  
  8.   string n[5]={"卡布奇諾   ","濃郁黑咖啡 ","焦糖瑪奇朵 ","黑森林蛋糕  ","原味起司蛋糕",};
  9.   int p[5]={160,210,125,95,65};
  10.   int a,q,sum=0;
  11.   for(int i=0; i<=4; i++)
  12.   {
  13.           cout<<"("<<i+1<<")"<<"  "<<n[i]<<"   "<<p[i]<<endl;
  14.   }
  15.   cout<<"(6)  結帳"<<endl<<endl;
  16.   re:
  17.   cout<<"請輸入商品代碼: ";
  18.   cin>>a;
  19.   if(a>=1 && a<=5)
  20.   {
  21.          cout<<"數量: ";
  22.          cin>>q;
  23.          if(q>=1)      
  24.          {
  25.                 sum=sum+p[a-1]*q;
  26.                 goto re;
  27.          }else
  28.          {
  29.                 cout<<"輸入錯誤!"<<endl;
  30.                 goto re;  
  31.          }
  32.   }else if(a==6)
  33.   {
  34.          goto checkout;
  35.   }else
  36.   {     
  37.          cout<<"輸入錯誤!"<<endl;
  38.          system ("pause");
  39.          goto re;
  40.   }
  41.   checkout:
  42.   cout<<"總共"<<sum<<"元!"<<endl;         
  43.   system ("pause");   
  44.   return 0;   
  45. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     int p, q, sum=0;
  7.     string name[7]={"黃金玫瑰",
  8.                     "食人花",
  9.                     "幽靈草",
  10.                     "瘋樹  ",
  11.                     "魔鬼藤蔓",
  12.                     "含兇草",
  13.                     "搖頭樹"};
  14.     int price[7]={7099,1598,2960,1800,4050,3999,6540};
  15.     cout<<"***  special植物專賣店  ***"<<endl<<endl;
  16.     for(int i=0; i<=6; i++)
  17.     {
  18.       cout<<"<"<<i+1<<">"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  19.     }
  20.     cout<<"<8>結帳"<<endl<<endl<<endl;
  21.     re:
  22.     cout<<"請輸入商品代碼: "<<endl;
  23.     cin>>p;
  24.     if(p>=1 && p<=7)
  25.     {
  26.            cout<<"數量: "<<endl;
  27.            cin>>q;
  28.            if(q>=1)
  29.            {
  30.               sum=sum+price[p-1]*9;
  31.               goto re;        
  32.            }
  33.     }
  34.     else if(p==8)
  35.     {
  36.            goto checkout;
  37.     }
  38.     else
  39.     {
  40.            cout<<"輸入錯誤!"<<endl;
  41.            goto re;
  42.     }
  43.     checkout:
  44.              cout<<"總共"<<sum<<"元"<<endl;
  45.     system("pause");
  46.     return 0;
  47. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main ()
  5. {
  6.   int p,q,sum=0;
  7.   string name[5]={"乒乓球",
  8.                   "棒球  ",
  9.                   "足球  ",
  10.                   "躲避球",
  11.                   "籃球  "};
  12.   int money[5]={50,100,125,200,600};
  13.   cout<<"~~~超酷球店~~~"<<endl<<endl;
  14.   cout<<"(商品價目表)"<<endl;  
  15.   
  16.   for(int i=0; i<=4; i++)
  17.   {
  18.       cout<<"("<<i+1<<")"<<name[i]<<"\t"<<money[i]<<"元"<<endl;
  19.   }
  20.   cout<<"(6)結帳"<<endl<<endl;
  21.   re:
  22.   cout<<"請輸入商品代碼: ";
  23.   cin>>p;
  24.     if(p>=1 && p<=5)
  25.     {
  26.         cout<<"數量: ";
  27.         cin>>q;
  28.         if(q>0)
  29.         {
  30.             sum=sum+money[p-1]*q;
  31.             goto re;
  32.         }else
  33.         {
  34.             cout<<"輸入錯誤!"<<endl;
  35.             goto re;  
  36.         }
  37.     }else if(p==6)
  38.     {
  39.         goto checkout;      
  40.     }else
  41.     {
  42.         cout<<"輸入錯誤!"<<endl;
  43.         goto re;     
  44.     }
  45.     checkout:
  46.     cout<<"總共"<<sum<<"元"<<endl<<endl;
  47.     system("pause");
  48.     return 0;

  49. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    cout<<"***Legend's Sports Store***"<<endl;
  7.   cout<<"The Price LIST"<<endl;
  8.   string name[7]={"Rose4               ",
  9.                  "NIKE Ambassader",
  10.                  "JORDAN FLIGHT",
  11.                  "ADIfast       ",
  12.                  "adizero crazy light",
  13.                  "NIKE hyperdunk 2013",
  14.                  "ADIZERO CRAZY QUICK"};
  15.   int price[7]={4500,
  16.                 3950,
  17.                 2400,
  18.                 2780,
  19.                 2950,
  20.                 2495,
  21.                 2154};
  22.      int p,q,sum=0;            
  23.     for(int i=0; i<=6; i++)
  24.     {
  25.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;     
  26.     }
  27.     cout<<"(8)結帳"<<endl<<endl;
  28.     re:
  29.     cout<<"請輸入商品代碼: ";
  30.     cin>>p;
  31.     if(p>=1 && p<=7)
  32.     {
  33.         cout<<"數量: ";
  34.         cin>>q;
  35.         if(q>0)
  36.         {
  37.             sum=sum+price[p-1]*q;
  38.             goto re;
  39.         }else
  40.         {
  41.             cout<<"輸入錯誤!"<<endl;
  42.             goto re;  
  43.         }
  44.     }else if(p==8)
  45.     {
  46.         goto checkout;      
  47.     }else
  48.     {
  49.         cout<<"輸入錯誤!"<<endl;
  50.         goto re;     
  51.     }
  52.     checkout:
  53.     cout<<endl<<"總共"<<sum<<"元!"<<endl<<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]={"超級瑪利歐","坦克大戰","決勝時刻10","戰地風雲4",
  7.                     "炸彈人","變形金剛","榮譽勳章"};                  
  8.     int price[7]={120,110,1900,1450,100,599,399};     
  9.     int p,q,sum=0;      
  10.    
  11.     cout<<"@@@無敵電玩店@@@"<<endl<<endl;
  12.     cout<<"[商品價目表]"<<endl;
  13.     for(int i=0; i<=6; i++)
  14.     {
  15.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;     
  16.     }
  17.     cout<<"(8)結帳"<<endl<<endl;
  18.     re:
  19.     cout<<"輸入商品代碼: ";
  20.     cin>>p;
  21.     if(p>=1 && p<=7)
  22.     {
  23.         cout<<"你要的數量: ";
  24.         cin>>q;
  25.         if(q>0)
  26.         {
  27.             sum=sum+price[p-1]*q;
  28.             goto re;
  29.         }else
  30.         {
  31.             cout<<"Error!"<<endl;
  32.             goto re;  
  33.         }
  34.     }else if(p==8)
  35.     {
  36.         goto checkout;      
  37.     }else
  38.     {
  39.         cout<<"Error!"<<endl;
  40.         goto re;     
  41.     }
  42.     checkout:
  43.     cout<<endl<<"共"<<sum<<"元!"<<endl<<endl;
  44.     system("pause");
  45.     return 0;
  46. }
複製代碼

TOP

返回列表