本帖最後由 洪榜蔓 於 2017-3-4 15:11 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- system("cls");
- int p,q,sum=0;
- string name[]={"iPhone1","iPhone2","iPhone3","iPhone4","iPhone5","iPhone6","iPhone7"};
- int price[]={19999,29999,30000,32000,34000,38000,40000};
- cout<<"#iPhone專賣店#"<<endl<<endl;
- cout<<"[商品價目表]"<<endl;
- for(int i=0; i<7; i++)
- {
- cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
- cout<<"(8)結帳"<<endl<<endl;
- re2:
- cout<<"請輸入商品代碼: ";
- cin>>p;
- if(p==8)
- {
- goto checkout;
- }else if(p>=1 && p<=7)
- {
- cout<<"數量: ";
- cin>>q;
- sum+=price[p-1]*q
- goto re2;
- }else
- {
- goto re;
- }
- checkout:
- cout<<endl<<"總共"<<sum<<"元~"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |