- #include <cstdlib>
- #include <iostream>
- using namespace std;
- int main()
- {
- int buy[7];
- int tim[7];
- int total=0;
- int num,many,time=0,yes,money,give,give1000,give500,give100,give50,give10,give1,last;
- string name[7]={"(1)搖控汽車 ","(2)飛機模型 ","(3)足球 ","(4)拼圖 ","(5)玩具槍 ","(6)可愛玩偶 ","(7)籃球 "};
- int price[7]={450,550,325,200,660,150,380};
- cout<<" 智能玩具店"<<endl;
- cout<<"[商品價目表]"<<endl;
- while(true)
- {
- for(int i=0;i<=6;i++)
- {
- cout<<name[i]<<price[i]<<"元";
- cout<<endl;
- }
- cout<<"輸入(8)結帳"<<endl;
- while(true)
- {
- cout<<"請輸入商品代碼: ";
- cin>>num;
- if(num==8)
- break;
- buy[time]=num;
- cout<<"數量: ";
- cin>>many;
- tim[time]=many;
- total=total+(price[num-1]*many);
- time++;
- }
- cout<<endl;
- cout<<"[購物清單]"<<endl;
- cout<<"--------------------------------"<<endl;
- for(int i=0;i<time;i++)
- {
- int j=0,k=0;
- j=buy[i];
- k=tim[i];
- cout<<name[j]<<" "<<price[j]<<"元 * "<<k<<"個"<<endl;
- }
- cout<<"-------------------------------"<<endl;
- cout<<"總共"<<total<<"元!"<<endl;
- cout<<endl;
- cout<<"1-正確無誤 2-重新選購 ";
- cin>>yes;
- if(yes==1)
- break;
- }
- while(true)
- {
- cout<<endl;
- cout<<"請付帳: ";
- cin>>money;
- if(money<total)
- cout<<"您付的錢不夠,還差"<<total-money<<"元!"<<endl;
- else
- break;
- }
- if(money>total)
- {
- give=money-total;
- }
- if(give>1000)
- {
- give1000=give/1000;
- last=give%1000;
- }
- else if(last>500)
- {
- give500=last/500;
- last=last%500;
- }
- else if(last>100)
- {
- give500=last/100;
- last=last%100;
- }
- else if(last>50)
- {
- give500=last/50;
- last=last%50;
- }
- else if(last>10)
- {
- give500=last/10;
- last=last%10;
- }
- else if(last>1)
- {
- give500=last/1;
- last=last%1;
- }
- cout<<"找您"<<give<<"元!"<<endl;
- if(give1000!=0)
- {
- cout<<"一千元鈔票"<<give1000<<"張"<<endl;
- }
- else if(give500!=0)
- {
- cout<<"五百元鈔票"<<give500<<"張"<<endl;
- }
- else if(give100!=0)
- {
- cout<<"一百元鈔票"<<give100<<"張"<<endl;
- }
- else if(give50!=0)
- {
- cout<<"五十元硬幣"<<give50<<"枚"<<endl;
- }
- else if(give10!=0)
- {
- cout<<"五十元硬幣"<<give10<<"枚"<<endl;
- }
- else if(give1!=0)
- {
- cout<<"五十元硬幣"<<give1<<"枚"<<endl;
- }
-
- system("PAUSE");
- return 0;
- }
複製代碼 |