Board logo

標題: 購物系統 (二) [打印本頁]

作者: 陳品肇    時間: 2019-2-16 10:18     標題: 購物系統 (二)

本帖最後由 陳品肇 於 2019-2-16 14:39 編輯

[attach]5936[/attach]
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.   cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  7.   cout<<"[商品價目表]"<<endl;
  8.   
  9.   string a[7]={"遙控器車","飛機模型","足球  ",
  10.                "拼圖  ","玩具槍 ","可愛玩偶","籃球  "};
  11.   int price[7]={450,550,325,200,660,
  12.                150,380 };
  13.   int p,q,sum=0;    //p商品代碼   q商品數量
  14.   for(int i=0;i<7;i++)
  15.   {
  16.       cout<<"("<<i+1<<")"<<a[i]<<"\t"<<price[i]<<"元"<<endl;
  17.   }  
  18.   cout<<"(8)結帳"<<endl<<endl;
  19.   
  20.   re:
  21.   cout<<"請輸入商品代碼: ";
  22.   cin>> p;
  23.   
  24.   if(p>=1 && p<=7)
  25.   {   
  26.      cout<<"數量: ";
  27.      cin>> q;
  28.      if(q>0)  //數量>0
  29.      {      
  30.         sum= sum+ price[p-1]*q;  //計算總金額
  31.         goto re;   
  32.      }else   //數量<0
  33.      {
  34.           cout<<"您輸入的數量有誤!!"<<endl;
  35.           goto re;
  36.      }
  37.   }else if(p==8)
  38.   {
  39.       goto checkout;
  40.   }else
  41.   {
  42.        cout<<"您輸入的代碼有錯!!"<<endl;
  43.        goto re;
  44.   }
  45.   
  46.   checkout:
  47.   cout<<"總金額: "<<sum<<"元"<<endl;
  48.   
  49.   system("pause");
  50.   return 0;

  51. }
複製代碼

作者: 曲書辰    時間: 2019-2-16 14:26

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.         int c=0,sum=0,h;
  7.         int n[7]={450,550,325,200,660,150,380};
  8.         string s[7]={"遙控器車","飛機模型","足球     ","拼圖     ","玩具槍","可愛玩偶","籃球     "};
  9.         cout<<"***智能玩具店***"<<endl;
  10.         cout<<endl;
  11.         cout<<"[商品價目表]"<<endl;
  12.         for(int i=0;i<7;i++)
  13.         {
  14.                 cout<<"<"<<i+1<<">"<<s[i]<<"\t"<<n[i]<<endl;
  15.          }
  16.         cout<<"(8)結帳"<<endl;
  17.         re:
  18.         cout<<"請輸入商品代碼:";
  19.         cin>>c;
  20.         if (c>=1 && c<=7)
  21.         {
  22.            cout<<"數量:";
  23.            cin>>h;
  24.            if(h>0)
  25.            {
  26.             sum+=n[c-1]*h;   
  27.            }else
  28.            {
  29.                 cout<<"錯誤"<<endl;
  30.            }
  31.            
  32.            goto re;
  33.         }else if(c==8)
  34.         {
  35.                    cout<<"總共:"<<sum<<endl;
  36.         }else
  37.         {
  38.             cout<<"輸入失敗"<<endl;
  39.              goto re;
  40.          }        
  41.       
  42.       
  43.         
  44.         system("pause");
  45.         return 0;
  46.         
  47. }
複製代碼

作者: 章幼莛    時間: 2019-2-16 14:39

本帖最後由 章幼莛 於 2019-2-16 14:46 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n,x,sum;
  7.     cout<<"☆★☆智能玩具店☆★☆"<<endl;
  8.     cout<<endl;
  9.     cout<<"[商品價目表]"<<endl;
  10.    
  11.     string f[7]={"遙控汽車",
  12.                  "飛機模型",
  13.                  "足球    ",
  14.                  "拼圖    ",
  15.                  "玩具槍  ",
  16.                  "可愛玩偶",
  17.                  "籃球    "};
  18.     int g[7]={450,550,325,200,660,150,380};
  19.     for(int i=0;i<7;i++)
  20.     {
  21.             cout<<"("<<i+1<<")"<<f[i]<<"\t"<<g[i]<<"元"<<endl;
  22.     }
  23.    
  24.     cout<<"(8)結帳"<<endl;
  25.     cout<<endl;
  26.    
  27.     re:
  28.     cout<<"請輸入商品代碼:";
  29.     cin>>n;
  30.    
  31.     if(n>=1 && n<=7)
  32.     {
  33.           cout<<"數量:";
  34.           cin>>x;
  35.          
  36.           if(x>=0)
  37.           {
  38.                   sum=sum+g[n-1]*x;
  39.                   goto re;
  40.           }else
  41.           {
  42.                   cout<<"您輸入的數量有誤"<<endl;
  43.                   goto re;
  44.           }
  45.     }else if(n==8)
  46.     {
  47.           goto checkout;
  48.     }else
  49.     {
  50.           cout<<"您輸入的商品代碼有誤!"<<endl;
  51.           goto re;
  52.     }
  53.    
  54.     checkout:
  55.     cout<<"總金額:"<<sum<<"元"<<endl;
  56.    
  57.     system("pause");
  58.     return 0;
  59. }
複製代碼
回復 1# 陳品肇
作者: 吳孟修    時間: 2019-2-16 14:43

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a[7]={450,550,325,200,660,150,380};
  7.     string b[7]={"遙控汽車","飛機模型","足球  ","拼圖  ","玩具槍 ","可愛玩偶","籃球  "};
  8.     cout<<"☆★☆智能玩具店☆★☆\n\n[商品價目表]\n";
  9.     for(int i=0;i<7;i++)
  10.     {
  11.         cout<<"("<<i+1<<")"<<b[i]<<"\t"<<a[i]<<"元"<<"\n";        
  12.     }
  13.     cout<<"(8)結帳\n\n";
  14.     int x,y,sum;
  15.     re:
  16.     cout<<"請輸入商品代碼: ";
  17.     cin>>x;
  18.     if(x>=1 && x<=7)
  19.     {
  20.         cout<<"數量: ";
  21.         cin>>y;
  22.         if(y>0)
  23.         {
  24.             sum=sum+a[x-1]*y;
  25.             goto re;
  26.         }
  27.         else
  28.         {
  29.             cout<<"您輸入的數量有誤"<<endl;
  30.             goto re;
  31.         }            
  32.     }
  33.     else if(x==8)
  34.     {
  35.         goto checkout;
  36.     }
  37.     else
  38.     {
  39.         cout<<"您輸入的代碼有誤"<<endl;
  40.         goto re;
  41.     }
  42.     checkout:
  43.     cout<<"\n總共是"<<sum<<"元"<<endl;         
  44.     system("pause");
  45.     return 0;
  46. }
複製代碼

作者: 洪寬瀧    時間: 2019-2-16 14:45

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.       int t,j,sum=0;
  7.     cout<<"***智能玩具店***"<<endl;
  8.         cout<<""<<endl;
  9.     cout<<"[商品價目表]"<<endl;
  10.     string items[7]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍","可愛玩偶","籃球 "};
  11.     int prices[7] = {450,550,325,200,660,150,380};
  12.           for(int i=0; i<7; i++)
  13.           {
  14.                 cout<<"("<<i+1<<")"<<items[i]<<"\t";
  15.             cout<<prices[i]<<"元"<<endl;
  16.         }
  17.          cout<<"(8)結帳"<<endl<<endl;
  18.          
  19.          re:
  20.          cout<<"請輸入商品代碼"<<endl;
  21.          cin>>t;
  22.          
  23.          if(t>=1 && t<=7)
  24.          {
  25.              cout<<"數量:";   
  26.              cin>>j;
  27.              if(j>0)
  28.              {
  29.              sum= sum+ prices[t-1]*j;
  30.              goto re;      
  31.              }else
  32.              {
  33.                cout<<"您輸入的數量有誤!!"<<endl;
  34.                goto re;   
  35.              }   
  36.                
  37.                         
  38.          }else if(t==8)
  39.          {
  40.          goto jeb;
  41.          }else
  42.          {
  43.            cout<<"您輸入的代碼有誤"<<endl;
  44.            goto re;
  45.          }
  46.          jeb:
  47.          cout<<"總金額: "<<sum<<"元"<<endl;
  48.     system("pause");
  49.     return 0;
  50. }
  51.       
  52.    
複製代碼

作者: 吳孟書    時間: 2019-2-16 14:50

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

作者: 王瑞喻    時間: 2019-2-16 14:50

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





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2