- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- start:
- string name[7]={"超級瑪利歐","坦克大戰","決勝時刻10","戰地風雲4",
- "炸彈人","變形金剛","榮譽勳章"};
- int price[7]={120,110,1900,1450,100,599,399};
- int qty[7]={0,0,0,0,0,0,0};
- int p,q,sum=0;
- int option;
- int pay,money;
- cout<<"無敵電玩店"<<endl<<endl;
- cout<<"[商品價目表]"<<endl;
- for(int i=0; i<=6; i++)
- {
- cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
- }
- cout<<"(8)結帳"<<endl<<endl;
- re:
- cout<<"輸入商品代碼: ";
- cin>>p;
- if(p>=1 && p<=7)
- {
- cout<<"你要的數量: ";
- cin>>q;
- if(q>0)
- {
- sum+=price[p-1]*q;
- qty[p-1]+=q;
- goto re;
- }else
- {
- cout<<"Error"<<endl;
- goto re;
- }
- }else if(p==8)
- {
- goto checkout;
- }else
- {
- cout<<"Error"<<endl;
- goto re;
- }
- checkout:
- cout<<endl<<"[購物清單]"<<endl;
- cout<<"============================="<<endl;
- for(int i=0; i<=6; i++)
- {
- if(qty[i]!=0)
- cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
- }
- cout<<"============================="<<endl;
- cout<<"共 "<<sum<<"元"<<endl<<endl;
- cout<<"1-正確 2-重新選購";
- cin>> option;
- if(option==1)
- {
- go to pay;
- }else if (option==2)
- {
- system ("cls");
- go to start;
- }
- pay:
- cout<<endl<<"請輸入你付的金額:";
- cin>>pay;
- money=pay-sum;
- if (money==0)
- {
- cout"剛好!慢走"<<endl;
- }else if (money<0)
- {
- cout<<"不夠!"<<-money<<"元!"endl;
- go to pay;
- }else
- {
- cout<<"找你"<<money<<"元"<<endl;
- if(money>=100)
- {
- cout<<"千元鈔票"<<money/1000<<"張"<<endl;
- money=money%1000;
- }
- if(money>=500)
- {
- cout<<"五百元鈔票"<<money/500<<"張"<<endl;
- money=money%500;
- }
- if(money>=100)
- {
- cout<<"一百元鈔票"<<money/100<<"張"<<endl;
- money=money%100;
- }
- if(money>=50)
- {
- cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
- money=money%50;
- }
- if(money>=10)
- {
- cout<<"十元硬幣"<<money/10<<"枚"<<endl;
- money=money%10;
- }
- if(money>=1)
- {
- cout<<"一元硬幣"<<money/1<<"枚"<<endl;
- }
- }
- system("pause");
- return 0;
- }
複製代碼 |