- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- cout<<"***智能玩具店***"<<endl<<endl;
- cout<<"[商品價目表]"<<endl;
-
- string a[5]={"bmw","法拉利","藍寶潔尼 ",
- "賓士 ","奧迪 "};
- int price[5]={400,550,600,250,150,};
- int p,q,sum=0;
- for(int i=0;i<5;i++)
- {
- cout<<"("<<i+1<<")"<<a[i]<<"\t"<<price[i]<<"萬元"<<endl;
- }
- cout<<"(6)結帳"<<endl<<endl;
- re:
- cout<<"請輸入商品代碼: ";
- cin>> p;
- if(p>=1 && p<=5)
- {
- cout<<"數量: ";
- cin>> q;
- if(q>0)
- {
- sum= sum+ price[p-1]*q;
- goto re;
- }
- }else if(p==6)
- {
- goto checkout;
- }
- else
- {
- cout<<"error"<<endl;
- goto re;
- }
- checkout:
- cout<<"總金額: "<<sum<<"萬元"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |