- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main(){
- while(true){
- system("cls");
- int p,q, sum = 0;
- int t[7]={0};
- string name[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
- int price[]={450,550,325,200,660,150,380};
- cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
- cout<<"[商品價目表]"<<endl;
- for(int i=0;i<7;i++){
- cout<<"<"<<i+1<<">"<<name[i]<<"\t"<<price[i]<<"元"<<endl;}
- cout<<"<8>"<<"結帳"<<endl;
- while(true){
- cout<<"請輸入商品代碼"<<endl;
- cin>>p;
- if(p==8)
- break;
- else if(p>=1&&p<=7){
- cout<<"數量:";
- cin>>q;
- sum+=price[p-1]*q;
- t[p-1]+=q;
- }
- else{
- cout<<"無效的商品代碼,請重新輸入"<<endl;
- }
- }
- cout<<"=================="<<endl;
- cout<<"[購物清單]"<<endl;
- for(int i=0;i<7;i++){
- if(t[i]>0)
- cout<<name[i]<<"\t\t"<<price[i]<<"*"<<t[i]<<"個"<<endl;
- }
- cout<<"===================="<<endl;
- cout<<endl<<"總共"<<sum<<"元!"<<endl;
- int option;
- cout<<"1-正確無誤 2-重新選購";
- cin>>option;
- switch(option){
- case 1:
- cout<<"請付帳:";
- int money;
- cin>>money;
- if(money<sum)
- cout<<"付款金額不足,還差"<<sum-money<<"元"<<endl;
- else{
- cout<<"找您"<<money-sum<<"元";
- int c=money-sum;//change
- {
- if(c>=500)
- cout<<"500元鈔票"<<c/500<<"張"<<endl;
- c%=500;
- if (c<500&&c>=100)
- cout<<"100元鈔票"<<c/500<<"張"<<endl;
- c%=100;
- if(c>=50&&c<100)
- cout<<"50元硬幣"<<c/50<<"個"<<endl;
- c%=50;
- if(c>=10&&c<50)
- cout<<"10元硬幣"<<c/10<<"個"<<endl;
- c%=10;
- if(c>=5&&c<10)
- cout<<"5元硬幣"<<c/5<<"個"<<endl;
- c%=5;
- if(c>=1&&c<5)
- cout<<"1元硬幣"<<c/1<<"個"<<endl;
- c%=1;
- }
- }
- break;
- case 2:
- continue;
- default:
- cout<<"Error,無效的選擇"<<endl;
- break;
- }
- system("pause");
- }
- return 0;
- }
複製代碼 |