本帖最後由 李泳霖 於 2024-12-6 19:44 編輯
新增 "購物清單" 功能,使結帳時能不只計算出價錢,還能列出細目。
參考執行畫面如下:
 - #include<iostream>
- using namespace std;
- int main()
- {
- string n[7]={"遙控器車","飛機模型","足球 ","拼圖 ","玩具槍","可愛玩偶","籃球 "};
- int p[7]={450,550,325,200,660,150,380};
- int t=0,a,b;
- cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
- cout<<"[商品價目表]"<<endl;
- for(int i=0;i<7;i++)
- {
- cout<<"("<<i+1<<")"<<n[i]<<"\t"<<p[i]<<"元"<<endl;
- }
- cout<<"(8)結帳"<<endl;
- re:
- cout<<"請輸入商品代碼:";
- cin>>a;
- if(a==8)
- goto checkout;
- cout<<"數量:";
- cin>>b;
- t+=p[a-1]*b;
- goto re;
- checkout:
- cout<<"總共:"<<t<<"元"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |