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

TOP

返回列表