- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int p,q,sum=0;
- string name[7]={"飛盤 ",
- "熊寶寶",
- "足球 ",
- "玩具槍",
- "拼圖 ",
- "筆記本",
- "鉛筆 ",};
- int price[7]={300,550,230,120,90,20,5};
- cout<<"☆★☆智能玩具店☆★☆"<<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<<"請輸入商品代碼:";
- cin>>p;
- if(p==8)
- {
- break;
- }
- else if(p>=1 && p<=7)
- {
- cout<<"數量:";
- cin>>q;
- if(q<=0)
- {
- cout<<"wrong!"<<endl;
- continue;
- }
- sum+=(price[p-1])*q;
- }
- else
- {
- cout<<"wrong!"<<endl;
- continue;
- }
- }
- cout<<endl<<"總共"<<sum<<"元!"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |