- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- system("cls");
- int price, pay;
- cout<<"智慧找零系統"<<endl;
- cout<<"輸入商品價格";
- cin>>price;
- if(price<=0){
- goto re;
- }
- cout<<"客人付多少錢";
- cin>>pay;
- if(pay>1000){
- cout<<"錢太多?";
- goto re;
- }
- int money=pay-price;
- if(money<0){
- cout<<"錢不夠,差"<<-money<<"元";
- }
- else if(money==0){
- cout<<"剛剛好,謝謝光臨";
- }
- else if(money>0){
- cout<<"找您"<<money<<"元"<<endl;
- if(money>=500 && money<1000){
- cout<<"五百元"<<money/500<<"張"<<endl;
- money%=500;
- }
- if(money>=100){
- cout<<"一百元"<<money/100<<"張"<<endl;
- money%=100;
- }
- if(money>=50){
- cout<<"五十元"<<money/50<<"枚"<<endl;
- money%=50;
- }
- if(money>=10){
- cout<<"十元"<<money/10<<"枚"<<endl;
- money%=10;
- }
- if(money>=5){
- cout<<"五元"<<money/5<<"枚"<<endl;
- money%=5;
- }
- if(money>0){
- cout<<"一元"<<money<<"枚"<<endl;
- }
- }
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |