本帖最後由 呂得銓 於 2023-5-17 19:36 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- string name[]={"遙控汽車","飛機模型","足球\t","拼圖\t","玩具槍","可愛玩偶","籃球\t"};
- int price[]={450,550,325,200,660,150,380};
- cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
- cout<<"[商品價目表]"<<endl;
- for(int i=0;i<=6;i++)
- {
- cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<endl;
- }
- cout<<"(8)結帳"<<endl;
- int option,qty,sum=0;
- re:
- cout<<"你要買什麼?";
- cin>>option;
- if(option>=1 and option<=7)
- {
- cout<<"你要買幾個?";
- cin>>qty;
- sum=sum+(price[option-1]*qty);
- goto re;
- }
- else if(option==8)
- {
- goto checkout;
- }
- checkout:
- cout<<"總共="<<sum<<"元"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |