返回列表 發帖
本帖最後由 黃崇維 於 2013-7-6 15:18 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int price[]={10000,12000,12300,12340,12345,123456,1234567};
  7.      int p, q, money, pay, sum=0;
  8.      cout<<"崇維智能電腦房屋店"<<endl<<endl;
  9.      cout<<"[電腦價目表]"<<endl;
  10.      cout<<"(1)一星級電腦\t10000元"<<endl;
  11.      cout<<"(2)二星級電腦\t12000元"<<endl;
  12.      cout<<"(3)三星級電腦\t12300元"<<endl;
  13.      cout<<"(4)四星級電腦\t12340元"<<endl;
  14.      cout<<"(5)五星級電腦\t12345元"<<endl;
  15.      cout<<"(6)六星級電腦\t123456元"<<endl;
  16.      cout<<"(7)七星級電腦\t1234567元"<<endl;
  17.      cout<<"(8)結帳"<<endl;
  18.      start:
  19.      cout<<"請輸入商品代碼: ";
  20.      cin>>p;
  21.      if(p==8)
  22.      {
  23.           goto checkout;
  24.      }else if(p>=1 && p<=7)
  25.      {
  26.           cout<<"請輸入數量:";
  27.           cin>>q;
  28.           if(q>0)
  29.           {
  30.               sum=sum+price[p-1]*q;
  31.               goto start;
  32.           }else
  33.           {
  34.               cout<<"輸入錯誤!"<<endl;
  35.               goto start;
  36.           }else
  37.        {
  38.            cout<<"輸入錯誤!"<<endl;
  39.            goto start;     
  40.        }
  41.      }         
  42.      checkout:
  43.      cout<<endl<<"總共"<<sum<<"元!"<<endl;
  44.      system("pause");
  45.      return 0;   
  46. }     
複製代碼

TOP

返回列表