返回列表 發帖

購物系統(二)

本帖最後由 周政輝 於 2018-3-24 12:41 編輯

新增 "請輸入商品代碼:" 與 "數量:" 的選項,
並於結帳時計算出總共多少錢, 執行畫面如下圖所示.
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[7]={"(1)搖控汽車","(2)玩具車","(3)遙控直升機","(4)足球","(5)籃球","(6)棒球","(7)玩具熊"} ;
  7.     int num[7]={500,1000,540,450,660,5,10} ;
  8.     cout<<"玩具店"<<endl;
  9.     cout<<"價目表"<<endl;
  10.     for(int i=0;i<7;i++)
  11.     {
  12.       cout<<name[i]<<num[i]<<endl;
  13.     }
  14.     cout<<endl;
  15.     int productnumber=0;
  16.     int count=0;
  17.     int total=0;
  18.     cout<<"輸入-1離開"<<endl;

  19.     while (true)
  20.     {

  21.     cout<<"請輸入商品代碼"<<endl;
  22.     cin>>productnumber;
  23.     if(productnumber==-1)
  24.     {
  25.     break;
  26.     }
  27.     cout<<"請輸入數量"<<endl;
  28.     cin>>count;
  29.     total=total+num[productnumber-1]*count;
  30.     }
  31.    
  32.     cout<<"總金額為"<<total;
  33.     system("pause");
  34.     return 0;
  35. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     cout<<"智能玩具店"<<endl;
  7.     string num[7]={"(1)遙控車","(2)遙控飛機","(3)足球  ","(4)拼圖  ","(5)籃球  ","(6)玩具槍","(7)娃娃"};
  8.     int n[7]={750,550,555,78,885,1999,85};
  9.     for(int i=0;i<7;i++)
  10.     {
  11.       cout<<num[i]<<"\t";     
  12.       cout<<n[i]<<"\t";
  13.       cout<<endl;
  14.     }
  15.     int a=0;
  16.     int z=0;
  17.     int w=0;
  18.      cout<<"輸入-1離開:"<<endl;
  19.      while(true)
  20.      {
  21.     cout<<"商品代碼:"<<endl;
  22.     cin>>a;
  23.     if(a==-1)
  24.     {
  25.     break;
  26.     }
  27.     cout<<"數量:"<<endl;
  28.     cin>>z;
  29.     w= w+n[a-1]*z;
  30.     }
  31.     cout<<"總金額:"<<w<<endl;
  32.     system("pause");
  33.      return 0;     
  34. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[7]={"(1)搖控汽車","(2)玩具車","(3)遙控直升機","(4)足球","(5)籃球","(6)棒球","(7)玩具熊"} ;
  7.     int num[7]={500,1000,540,450,660,5,10} ;
  8.     cout<<"玩具店"<<endl;
  9.     cout<<"價目表"<<endl;
  10.     for(int i=0;i<7;i++)
  11.     {
  12.       cout<<name[i]<<num[i]<<endl;
  13.     }
  14.     cout<<endl;
  15.     int productnumber=0;
  16.     int count=0;
  17.     int total=0;
  18.     cout<<"輸入-1離開"<<endl;

  19.     while (true)
  20.     {

  21.     cout<<"請輸入商品代碼"<<endl;
  22.     cin>>productnumber;
  23.    
  24.     cout<<"請輸入數量"<<endl;
  25.     cin>>count;
  26.      if(productnumber==-1)
  27.     {
  28.    
  29.     total=total+num[count-1]*count;
  30.     break;
  31.     }
  32.     };
  33.     cout<<"總金額為"<<total;
  34.     system("pause");
  35.     return 0;
  36. }
複製代碼

TOP

本帖最後由 吳秉翰 於 2018-3-10 15:13 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string item []=
  7.     {
  8.     "(1)遙控汽車    ",
  9.     "(2)飛機模型    ",
  10.     "(3)足球        ",
  11.     "(4)拼圖        ",
  12.     "(5)玩具槍      ",
  13.     "(6)可愛玩偶    ",
  14.     "(7)籃球        ",
  15.     };
  16.     int num []={450,550,325,200,660,150,380};
  17.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl<<"[商品價目表]"<<endl;
  18.     for(int i=0;i<7;i++)
  19.     {
  20.         cout<<item[i]<<num[i]<<"元"<<"\t"<<endl;
  21.     }
  22.      int pn = 0;
  23.      int count =0;
  24.      int total = 0;   
  25.      while(true)
  26.     {
  27.         cout<<"代碼:";
  28.         cin>>pn;
  29.         if(pn==8)
  30.         {
  31.             break;      
  32.         }
  33.         cout<<"數目:";
  34.         cin>>count;
  35.         total=total+num[pn-1]*count;
  36.     }
  37.     cout<<total<<"元"<<endl;
  38.     system("pause");
  39.     return 0;
  40. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    string item []={
  7.    "(1)遙控汽車     ",
  8.    "(2)飛機模型     ",
  9.    "(3)足球         ",
  10.    "(4)拼圖         ",
  11.    "(5)玩具槍       ",
  12.    "(6)可愛玩偶     ",
  13.    "(7)籃球         "};   
  14.    int num []={450,550,325,200,660,150,380};
  15.    cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  16.    cout<<"[商品價目表]"<<endl;
  17.    for(int i=0;i<7;i++)
  18.    {     
  19.      cout<<item[i]<<num[i]<<"元"<<"\t"<<endl;
  20.    }
  21.    
  22.    int total=0;
  23.    int pn=0;
  24.    int count=0;
  25.    cout<<"輸入-1後離開"<<endl;
  26.    while(true)
  27.    {
  28.     cout<<"請輸入商品代碼"<<endl;
  29.     cin>>pn;
  30.     if(pn==-1){
  31.     break;
  32.    }
  33.     cout<<"數目:";
  34.     cin>>count;
  35.    
  36.     total=total+num[pn-1]*count;
  37.    }

  38.    cout<<total<<"元"<<endl;  
  39.    
  40.    
  41.    system("pause");
  42.    return 0;
  43. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    cout<<"智能玩具店"<<endl;
  7.      string name [7]={"(1)遙控汽車","(2)遙控飛機","(3)足球","(4)評圖","(5)玩具槍","(6)可愛玩偶","(7)籃球"};   
  8.     int num[7]={450,550,325,200,660,150,380};  
  9.     for (int i=0;i<7;i++)
  10.     {
  11.           cout<<name[i]<<"\t";
  12.        cout<<num[i]<<endl;
  13. }
  14. cout<<endl;
  15. int productnumber=0;
  16. int count=0;
  17. int total=0;

  18. cout<<"請輸入-1離開"<<endl;
  19. while(true)
  20. {
  21. cout<<"商店代碼"<<endl;
  22. cin>>productnumber;
  23. if(productnumber==-1)
  24. {break;
  25. }
  26. cout<<"數量"<<endl;
  27. cin>>count;
  28. total=total+num[count-1]*count;

  29. }
  30. cout<<"總金"<<total<<endl;
  31.     system("pause");  
  32.   return 0;
  33. }   
複製代碼

TOP

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

TOP

  1. #include <cstdlib>
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.     int total=0;
  7.     int num,many;
  8.     string name[7]={"搖控汽車    ","飛機模型    ","足球        ","拼圖        ","玩具槍      ","可愛玩偶    ","籃球        "};
  9.     int price[7]={450,550,325,200,660,150,380};
  10.     cout<<"     智能玩具店"<<endl;
  11.     cout<<"商品\t\t金額"<<endl;
  12.     for(int i=0;i<=6;i++)
  13.     {
  14.             cout<<"("<<i+1<<")"<<name[i]<<price[i]<<"元";
  15.             cout<<endl;
  16.     }
  17.     cout<<"輸入(8)結帳"<<endl;
  18.     while(true)
  19.     {
  20.                cout<<"請輸入商品代碼:  ";
  21.                cin>>num;
  22.                if(num==8)
  23.                break;
  24.                cout<<"數量:  ";
  25.                cin>>many;
  26.                    total=total+(price[num-1]*many);
  27.     }
  28.     cout<<endl;
  29.     cout<<"總共"<<total<<"元!";
  30.     system("PAUSE");
  31.     return 0;
  32. }
複製代碼

TOP

返回列表