本帖最後由 李知易 於 2015-4-11 11:03 編輯
- #include<iostream>
- #include<cstdlib>
- #include "math.h"
- using namespace std;
- int main()
- {
- allre:
- system("cls");
- int p,pay,popo,money,opt,sum=0;
- string name[5]={"砍頭優惠卷","特效搖頭丸","自殺體驗卷","被打免費票","舒柔鼻涕蟲",};
- int price[5]={499,1998,8888,9999,99999};
- cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
- cout<<"[商品價目表]"<<endl;
- int qty[5]={0,0,0,0,0};
- for(int i=0; i<5; i++)
- {
- cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
- }
- cout<<"(8)結帳"<<endl<<endl;
- re:
- cout<<"請輸入商品代碼: ";
- cin>>p;
- if(p==8)
- goto checkout;
- else if(p>=1 && p<=7)
- {
- cout<<"數量: ";
- cin>>popo;
- if(popo<=0)
- {
- cout<<"輸入錯誤!"<<endl;
- goto re;
- }
- sum+=price[p-1]*popo;
- qty[p-1]+=popo;
- }
- else
- {
- cout<<"輸入錯誤!"<<endl;
- }
- goto re;
- checkout:
- cout<<endl<<"噁心清單"<<endl;
- cout<<"----------------------------------"<<endl;
- for (int i=0;i<5;i++)
- {
- if(qty[i]!=0)
- cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
- }
- cout<<"----------------------------------"<<endl;
-
- if(sum >= 5000)
- {
- cout<<"你消費"<<sum<<"元,恭喜你符合滿5000打九折優惠活動!"<<endl<<endl;
- cout<<"這一次的消費讓你省下!"<<(sum - round(sum * 0.9))<<"元"<<endl<<endl;
- sum = round(sum * 0.9);
- }
- else if(sum >= 4500)
- {
- cout<<"你消費"<<sum<<"元,恭喜你符合滿4500送砍頭優惠卷活動!"<<endl<<endl;
- }
-
- cout<<"總共"<<sum<<"元!"<<endl<<endl;
- cout<<"1-正確無誤"<<endl<<"2-重新選購"<<endl;
- cin>>opt;
- if(opt==1)
- {
- goto change;
- }
- if(opt==2)
- {
- goto allre;
- }
- change:
- cout<<"請付錢:";
- cin>>pay;
- if(pay<=0)
- {
- cout<<endl<<"你是誰啊?!"<<endl<<endl;
- goto change;
- }
- money=pay-sum;
- if(money<0)
- {
- cout<<endl<<"錢不夠喔! 還差"<<-money<<"元!"<<endl<<endl;
- goto change;
- }else if(money==0)
- {
- cout<<endl<<"剛剛好! 銘謝惠顧!"<<endl<<endl;
- }else if(money>=1000)
- {
- cout<<endl<<"錢太多? 全部送我吧!"<<endl<<endl;
- goto change;
- }
- else
- {
- cout<<endl<<"需找客人"<<money<<"元"<<endl<<endl;
- if(money>=500)
- {
- cout<<"五百元鈔票"<<money/500<<"張"<<endl;
- money%=500; //money=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>=1)
- {
- cout<<"一元硬幣"<<money<<"枚"<<endl;
- }
- cout<<endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |