返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    cout<<"☆★☆智能玩具店☆★☆"<<endl;
  7.     int buy[7];
  8.     int buycount[7];
  9.     string j[7]=
  10.     {
  11.              "(1)遙控汽車",
  12.              "(2)飛機模型",
  13.              "(3)足球    ",
  14.              "(4)拼圖    ",
  15.              "(5)玩具槍  ",
  16.              "(6)可愛玩偶",
  17.              "(7)籃球    "
  18.     };
  19.    int n[7]=
  20.       {
  21.             450,
  22.             550,
  23.             325,
  24.             200,
  25.             660,
  26.             150,
  27.             380
  28.       };
  29.    
  30.     for(int i=0;i<7;i++)
  31.      {
  32.            cout<<j[i]<<"\t"<<n[i]<<"元"<<endl;
  33.      }
  34.     int king=0;
  35.     int index=0;
  36.     int num=0;
  37.     int count=0;
  38.     int total=0;
  39.      cout<<"輸入0結帳"<<endl;
  40.    while(true)
  41. {
  42.    while(true)
  43.    {
  44.      cout<<"請輸入商品代碼"<<endl;
  45.      cin>>num;   
  46.      if(num==0)
  47.      {   
  48.        break;
  49.      }
  50.      buy[index]=num;
  51.      cout<<"請輸入數量"<<endl;
  52.      cin>>count;
  53.      buycount[index]=count;
  54.      total=total+n[num-1]*count;   
  55.      index++;
  56.    }
  57.     cout<<"是否要繼續購買? (1)要 (2)不要"<<endl;
  58.     cin>>king;
  59.     if(king==1)
  60.     {
  61.     continue;
  62.     }
  63.     else
  64.     {
  65.     cout<<"[購物清單]"<<endl;
  66.     cout<<"--------------------------"<<endl;
  67.     for(int i=0;i<index;i++)
  68.     {
  69.     cout<<j[buy[i]-1]<<"  "<<n[buy[i]-1]<<"元 => "<<buycount[i]<<"個"<<endl;
  70.     }
  71.     cout<<"--------------------------"<<endl;
  72.     cout<<"總金額:"<<total<<endl;
  73.     break;
  74.     }
  75. }
  76.     system("pause");
  77.     return 0;
  78. }
複製代碼

TOP

返回列表