fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main(void)
  5. {
  6. char st;
  7. char ch='y';
  8. int pay,a,b,c,d,e,f,g,h,i,j,k;
  9. int total = 0;
  10. float z;
  11. do
  12. {
  13. cout<<"買";
  14. cin>>z;
  15. if(z>=900)
  16. z=z*0.8;
  17. else if (z>=500)
  18. z=z*0.9;
  19. else
  20. z=z*0.95;
  21.  
  22. total = total + z;
  23.  
  24. cout<<"繼續??(y/n)";
  25. cin>>ch;
  26. }
  27. while(ch=='y');
  28.  
  29. cout<<"應付金額"<<z<<endl;
  30. cout<<"付";
  31. cin>>pay;
  32. a=pay-total;
  33. if (a<0)
  34. cout<<"錯誤 \n";
  35. else
  36. {
  37. b=a/500;
  38. c=a%500;
  39. d=c/100;
  40. e=c%100;
  41. f=e/50;
  42. g=e%50;
  43. h=g/10;
  44. i=g%10;
  45. j=i/5;
  46. k=i%5;
  47. cout<<"找零="<<a<<endl;
  48. cout<<"500*"<<b<<endl<<"100*"<<d<<endl<<"50*"<<f<<endl<<"10*"<<h<<endl
  49. <<"5*"<<j<<endl<<"1*"<<k<<endl;
  50. }
  51. cin>>st;
  52. }
  53.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty