返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5. while(true){
  6. system("cls");
  7. int p,q, sum = 0;
  8. int t[7]={0};
  9. string name[]={"遙控汽車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    "};
  10. int price[]={450,550,325,200,660,150,380};
  11. cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  12. cout<<"[商品價目表]"<<endl;
  13. for(int i=0;i<7;i++){
  14. cout<<"<"<<i+1<<">"<<name[i]<<"\t"<<price[i]<<"元"<<endl;}
  15. cout<<"<8>"<<"結帳"<<endl;



  16. while(true){
  17. cout<<"請輸入商品代碼"<<endl;
  18. cin>>p;
  19.   if(p==8)
  20. break;
  21. else if(p>=1&&p<=7){
  22. cout<<"數量:";
  23. cin>>q;
  24. sum+=price[p-1]*q;
  25. t[p-1]+=q;
  26. }
  27. else{
  28. cout<<"無效的商品代碼,請重新輸入"<<endl;
  29. }

  30. }

  31. cout<<"=================="<<endl;
  32. cout<<"[購物清單]"<<endl;
  33. for(int i=0;i<7;i++){
  34.     if(t[i]>0)
  35. cout<<name[i]<<"\t\t"<<price[i]<<"*"<<t[i]<<"個"<<endl;

  36. }
  37. cout<<"===================="<<endl;


  38. cout<<endl<<"總共"<<sum<<"元!"<<endl;

  39. int option;
  40. cout<<"1-正確無誤  2-重新選購";
  41. cin>>option;
  42. switch(option){
  43. case 1:
  44.     cout<<"請付帳:";
  45.     int money;
  46.     cin>>money;
  47.     if(money<sum)
  48.         cout<<"付款金額不足,還差"<<sum-money<<"元"<<endl;
  49.     else{
  50. cout<<"找您"<<money-sum<<"元";
  51. int c=money-sum;//change
  52.     {
  53. if(c>=500)
  54.         cout<<"500元鈔票"<<c/500<<"張"<<endl;
  55. c%=500;
  56. if (c<500&&c>=100)
  57.         cout<<"100元鈔票"<<c/500<<"張"<<endl;
  58. c%=100;
  59. if(c>=50&&c<100)
  60. cout<<"50元硬幣"<<c/50<<"個"<<endl;
  61. c%=50;
  62. if(c>=10&&c<50)
  63. cout<<"10元硬幣"<<c/10<<"個"<<endl;
  64. c%=10;
  65. if(c>=5&&c<10)
  66. cout<<"5元硬幣"<<c/5<<"個"<<endl;
  67. c%=5;
  68. if(c>=1&&c<5)
  69. cout<<"1元硬幣"<<c/1<<"個"<<endl;
  70. c%=1;

  71. }




  72.     }
  73.     break;
  74. case 2:
  75.     continue;
  76. default:
  77.     cout<<"Error,無效的選擇"<<endl;
  78.     break;



  79. }

  80. system("pause");



  81. }



  82. return 0;
  83. }
複製代碼

TOP

返回列表