本帖最後由 黃崇維 於 2013-7-20 20:32 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- string name[]={"一星級電腦","二星級電腦","三星級電腦","四星級電腦","五星級電腦","六星級電腦","七星級電腦"};
- int price[]={10000,12000,12300,12340,12345,123456,1234567};
- int qty[]={0,0,0,0,0,0,0};
- int p, q, money, pay, sum=0, a;
- cout<<"崇維智能電腦房屋店"<<endl<<endl;
- cout<<"[電腦價目表]"<<endl;
- cout<<"(1)一星級電腦\t10000元"<<endl;
- cout<<"(2)二星級電腦\t12000元"<<endl;
- cout<<"(3)三星級電腦\t12300元"<<endl;
- cout<<"(4)四星級電腦\t12340元"<<endl;
- cout<<"(5)五星級電腦\t12345元"<<endl;
- cout<<"(6)六星級電腦\t123456元"<<endl;
- cout<<"(7)七星級電腦\t1234567元"<<endl;
- cout<<"(8)結帳"<<endl<<endl;
- start:
- cout<<"請輸入商品代碼: ";
- cin>>p;
- if(p==8)
- {
- goto checkout;
- }else if(p>=1 && p<=7)
- {
- 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<=6; i++)
- {
- if(qty[i]!=0)
- cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;
- }
- cout<<"-------------"<<endl;
- cout<<"\t\t總共"<<sum<<"元!"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |