- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- Q:
- system("cls");
- string com[8]={"紙10張","袋子","洋芋片","奶茶","書套","鍵盤","滑鼠","漫畫4本"};
- int mon[]={5,10,25,39,80,499,990,1499};
- cout<<"智能雜貨店 商品名稱"<<endl<<endl;
- cout<<"滿5000元享9折優惠!"<<endl<<endl;
- cout<<"編號"<<"\t"<<"名稱"<<"\t"<<"\t"<<"價格"<<endl;
- for(int i=0; i<8; i++)
- {
- cout<<"("<<i+1<<")"<<"\t"<<com[i]<<"\t"<<"\t"<<mon[i]<<"元"<<endl;
- }
- cout<<"(9)"<<"\t"<<"結帳"<<"\t"<<endl;
- re:
- int much[]={0,0,0,0,0,0,0,0};
- int mone[]={0,0,0,0,0,0,0,0};
- float y=0;
- int c=0;
- while(1)
- {
- int x=0,w=0;
- cout<<"請輸入商品編號:";
- cin>>x;
- if(x==9)
- break;
- else
- cout<<"請輸入數量:";
- cin>>w;
-
- if(x<=8 && x>=1){
- y+=mon[x-1]*w;
- much[x-1]+=w;
- mone[x-1]+=mon[x-1]*w;
- }else{
- cout<<"輸入錯誤"<<endl;
- }
-
- }
- for(int i=0; i<8; i++)
- cout<<"("<<i+1<<")"<<"\t"<<com[i]<<"\t"<<"\t"<<much[i]<<"個"<<" 小計"<<"\t"<<mone[i]<<"元"<<endl;
- if(y>=5000){
- cout<<"因滿5000元所以享九折優惠"<<endl;
- y=y*0.9;
- }
- cout<<"一共"<<y<<"元"<<endl;
- cout<<"1 重新選購 2 確定無誤:";
- cin>>c;
- if(c==2){
- int pay,money;
- cout<<"付了多少錢: ";
- cin>>pay;
- money=pay-y;
- if(money>=0)
- {
- cout<<endl<<"需找客人"<<money<<"元"<<endl<<endl;
- if(money>=500)
- {
- 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>=1)
- {
- cout<<"一元硬幣"<<money<<"枚"<<endl;
- }
- cout<<"謝謝惠顧"<<endl;
- }
- else{
- cout<<"錢不夠 還差"<<y-pay<<"元"<<endl;
- }
- }
- else if(c==1){
- goto re;
- }
- else
- cout<<"輸入錯誤"<<endl;
-
- system("pause");
- goto Q;
- return 0;
- }
複製代碼 |