- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int price[]={300,250,150,600,1000};
- 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;
- goto start;
- }else
- {
- cout<<"輸入錯誤"<<endl;
- goto start;
- }
- }else
- {
- cout<<"輸入錯誤"<<endl;
- goto start;
- }
- checkout:
- cout<<endl<<"總共"<<sum<<"元"<<endl;
- system ("pause");
- return 0;
- }
複製代碼 |