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. float z;
  10. do
  11. {
  12. cout<<"買";
  13. cin>>z;
  14. if(z>=900)
  15. z=z*0.8;
  16. else if (z>=500)
  17. z=z*0.9;
  18. else
  19. z=z*0.95;
  20.  
  21. cout<<"應付金額"<<z<<endl;
  22. cout<<"付";
  23. cin>>pay;
  24. a=pay-z;
  25. if (a<0)
  26. cout<<"錯誤 \n";
  27. else
  28. {
  29. b=a/500;
  30. c=a%500;
  31. d=c/100;
  32. e=c%100;
  33. f=e/50;
  34. g=e%50;
  35. h=g/10;
  36. i=g%10;
  37. j=i/5;
  38. k=i%5;
  39. cout<<"找零="<<a<<endl;
  40. cout<<"500*"<<b<<endl<<"100*"<<d<<endl<<"50*"<<f<<endl<<"10*"<<h<<endl
  41. <<"5*"<<j<<endl<<"1*"<<k<<endl;
  42. }
  43.  
  44. cout<<"繼續??(y/n)";
  45. cin>>ch;
  46. }
  47. while(ch=='y');
  48. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty