- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- system("cls");
- string a[]{"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 ",};
- int b[]={450,550,325,200,660,150,380};
- int c[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- int d[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
- cout<<"商品價目表"<<endl;
- for(int i=0; i<7; i++)
- {
- cout<<"<"<<i+1<<">"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
- }
- cout<<"<8>結帳"<<endl;
- cout<<endl;
- int x,y,z=-1,w=-1,sum=0;
- re2:
- cout<<"請輸入商品代碼:";
- cin>>x;
- if(x==8)
- {
- goto out;
- }
- else if(x>=1&&x<=7)
- {
- cout<<"請輸入購買數量:";
- cin>>y;
- z++;
- sum+=b[x-1]*y;
- c[z]+=y;
- d[z]+=x;
- goto re2;
- }
- else
- {
- cout<<"輸入錯誤"<<endl;
- goto re2;
- }
- out:
- cout<<endl;
- cout<<"[購物清單]"<<endl;
- cout<<"------------------------"<<endl;
- for(int i=0 ; i<=30 ;i++)
- {
- if(d[i]!=0)
- {
- cout<<a[d[i]-1]<<"\t"<<b[d[i]-1]<<"元*"<<c[i]<<"個"<<endl;
- }
- }
- cout<<"-------------------------"<<endl;
- cout<<endl<<"總共"<<sum<<"元!"<<endl;
- int q,r;
- re3:
- cout<<"1-正確無誤\t2-重新輸入";
- cin>>q;
- if(q==1)
- {
- goto out2;
- }
- else if(q==2)
- {
- goto re;
- }
- else
- {
- cout<<"輸入錯誤 重新輸入";
- goto re3;
- }
- out2:
- cout<<endl;
- cout<<"請付帳:";
- cin>>r;
- if(r<sum)
- {
- cout<<"您付的金額不足,還差"<<sum-r<<"元!"<<endl;
- goto out2;
- }
- else if(r>sum)
- {
- cout<<endl;
- cout<<"找您"<<r-sum<<"元"<<endl;
- int e=r-sum;
- if(e>=1000)
- cout<<"1000元鈔票"<<e/1000<<"張"<<endl;
- e%=1000;
- if(e>=500)
- cout<<"500元鈔票"<<e/500<<"張"<<endl;
- e%=500;
- if (e>=100)
- cout<<"100元鈔票"<<e/100<<"張"<<endl;
- e%=100;
- if(e>=50)
- cout<<"50元硬幣"<<e/50<<"個"<<endl;
- e%=50;
- if(e>=10)
- cout<<"10元硬幣"<<e/10<<"個"<<endl;
- e%=10;
- if(e>=5)
- cout<<"5元硬幣"<<e/5<<"個"<<endl;
- e%=5;
- if(z>=1)
- cout<<"1元硬幣"<<e/1<<"個"<<endl;
- }
- else if(r==sum)
- {
- cout<<"剛剛好,謝謝惠顧"<<endl;
- }
- else
- {
- cout<<"輸入錯誤 重新輸入"<<endl;
- goto out2;
- }
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |