- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- string name []={"小說", "漫畫", "雜誌", "字典", "百科全書",};
- int price[]={300,250,150,600,1000};
- int qty[]={0,0,0,0,0};
- int p,q,sum=0;
- cout<<"書店"<<endl<<endl;
- cout<<"[商品價目表]"<<endl;
- cout<<"(1)小說\t\t300元"<<endl;
- cout<<"(2)漫畫\t\t250元"<<endl;
- cout<<"(3)雜誌\t\t150元"<<endl;
- cout<<"(4)字典\t\t600元"<<endl;
- cout<<"(5)百科全書\t1000元"<<endl;
- cout<<"(6)結帳"<<endl<<endl;
- start:
- cout<<"請輸入商品代碼: ";
- cin>>p;
- if(p==6)
- {
- goto checkout;
-
- }else if(p>=1 && p<=5)
- {
- cout<<"請輸入數量: ";
- cin>>q;
- if(q>0)
- {
- sum=sum+price[p-1]*q;
- qty[p-1]=q;
- goto start;
- }else
- {
- cout<<"輸入錯誤"<<endl;
- goto start;
- }
- }else
- {
- cout<<"輸入錯誤"<<endl;
- goto start;
- }
- checkout:
- cout<<endl<<"[購物清單]"<<endl;
- cout<<"-----------------------"<<endl;
- for(int i=0; i<=4; i++)
- {
- if(qty[i]!=0)
- cout<<name[i]<<"\t"<<price[i]<<"元*"<<qty[i]<<"個"<<endl;
- }
- cout<<"-----------------------"<<endl;
- cout<<endl<<"總共"<<sum<<"元"<<endl;
- system ("pause");
- return 0;
- }
複製代碼 |