- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- string name[]={"屎一斤 ","坦克模型","魔球 ","藍圖 ","機關槍 ","驚悚玩偶","保齡球 "};
- int price[]={450,550,325,200,660,150,380};
- int qty[]={0,0,0,0,0,0,0};
- int p,q,sum=0;
- cout<<"$超能商店$"<<endl;
- cout<<"[商品價格]"<<endl;
- cout<<"(1)屎一斤\t550元"<<endl;
- cout<<"(2)坦克模型\t550元"<<endl;
- cout<<"(3)魔球\t\t325元"<<endl;
- cout<<"(4)藍圖\t\t200元"<<endl;
- cout<<"(5)機關槍\t660元"<<endl;
- cout<<"(6)驚悚玩偶\t150元"<<endl;
- cout<<"(7)保齡球\t380元"<<endl;
- cout<<"(8)結帳"<<endl<<endl;
- cout<<"[使用說明]"<<endl;
- cout<<"依序輸入想購買的商品與數量,如籃球兩顆請輸入'7 2'"<<endl;
- cout<<"選購完畢時輸入'8 8'進入結帳頁"<<endl<<endl;
- start:
- cout<<"在此輸入: ";
- cin>>p;
- if(p==8)
- {
- goto checkout;
- }
- else if(p>=1 && p<=7 && q>0)
- {
- sum=sum+price[p-1]*q;
- qty[p-1]=q;
- goto start;
- }else if(p==8 && q==8)
- {
- goto checkout;
- }else
- {
- cout<<"輸入錯誤!"<<endl;
- goto start;
- }
- checkout:
- cout<<endl<<"[購物清單]"<<endl;
- cout<<"-------------------------------------"<<endl;
- for(int i=0; i<=6; i++)
- {
- cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
- }
- if(qty[i]!=0)
- cout<<"-------------------------------------"<<endl;
- cout<<"\t\t總共"<<sum<<"元!"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |