本帖最後由 蔡季樺 於 2016-4-26 17:46 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- string name[8]={"火焰藥水","放屁藥水","作夢藥水","打呵欠藥水","超人藥水","打老師藥水","萬能藥水","結帳"};
- int inventory[7]={0,0,0,0,0,0,0};
- int money[7]={200,50,100,10,2000,1100,1000000};
- int commodity,quantity,checkout=0;
- cout<<"~~★☆★沒路用的藥水專賣店☆★☆~~"<<endl;
- cout<<"[價目表]"<<endl;
- for(int i=0; i<=6; i++)
- {
- cout<<"("<<i+1<<")"<<name[i]<<"\t"<<money[i]<<"元"<<endl;
- }
- cout<<"("<<"8"<<")"<<name[7]<<endl;
- while(true)
- {
- cout<<"請輸入想要買的商品代碼(結帳按8):";
- cin>>commodity;
- if(commodity<1 || commodity>8)
- continue;
- if(commodity==8)
- break;
- cout<<"請輸入要買的數量:";
- cin>>quantity;
- inventory[commodity-1]+=quantity;
- checkout+=quantity*money[commodity-1];
- }
- cout<<"〔購物清單〕"<<endl;
- cout<<"-----------------------------------"<<endl;
- for(int i=0;i<=6;i++)
- {
- if(inventory[i]!=0)
- {
- cout<<name[i]<<"\t";
- cout<<money[i]<<"\t元 * ";
- cout<<inventory[i]<<endl;
- }
- }
- if(checkout==0)
- cout<<"\t(空白)"<<endl;
- cout<<"-----------------------------------"<<endl;
- cout<<"總共要付"<<checkout<<"元!"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |