返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int p, q, sum=0;
  7.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  8.     string commodity[8]={"新生兒",
  9.                          "大小便",
  10.                          "阿嬤丸",
  11.                          "發瘋藥水",
  12.                          "甲狀腺",
  13.                          "廁所清潔劑",
  14.                          "山寨包包LV",
  15.                          "結帳"};
  16.     int price[7]={20,
  17.                   3000,
  18.                   500,
  19.                   20,
  20.                   600,
  21.                   10,
  22.                   8000,};
  23.     cout<<"[商品價目表]"<<endl;
  24.     for(int i=0; i<7; i++)
  25.     {
  26.             cout<<"("<<i+1<<")"<<commodity[i]<<"\t"<<price[i]<<"元"<<endl;
  27.     }
  28.     cout<<"(8)"<<commodity[7]<<endl<<endl;
  29.     while(true)
  30.     {
  31.         cout<<"請輸入商品代碼: ";
  32.         cin>>p;
  33.         if(p==8)
  34.         {
  35.             break;
  36.         }else if(p>=1 && p<=7)
  37.         {
  38.            cout<<"數量: ";
  39.            cin>>q;
  40.            if(q<=0)
  41.            {
  42.               cout<<"輸入錯誤!"<<endl;
  43.               continue;     
  44.            }   
  45.            sum+=(price[p-1]*q);
  46.         }else
  47.         {
  48.              cout<<"輸入錯誤!"<<endl;
  49.              continue;
  50.         }  
  51.     }cout<<endl<<"總共"<<sum<<"元!"<<endl;            
  52.     system("pause");
  53.     return 0;               
  54. }
複製代碼

TOP

返回列表