返回列表 發帖
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int buy[7];
  7.     int buycount[7];
  8.     cout<<"智能玩具店"<<endl;
  9.     string num[7]={"(1)遙控車","(2)遙控飛機","(3)足球  ","(4)拼圖  ","(5)籃球  ","(6)玩具槍","(7)娃娃"};
  10.     int n[7]={750,550,555,78,885,1999,85};
  11.     for(int i=0;i<7;i++)
  12.     {
  13.       cout<<num[i]<<"\t";     
  14.       cout<<n[i]<<"\t";
  15.       cout<<endl;
  16.     }
  17.     int a=0;
  18.     int z=0;
  19.     int w=0;
  20.     int index=0;
  21.     int number=0;
  22.    
  23.      cout<<"輸入-1離開:"<<endl;
  24.    
  25.      while (true)
  26.     {
  27.      
  28.      while(true)
  29.      {
  30.          cout<<"商品代碼:"<<endl;
  31.          cin>>a;
  32.          if(a==-1)
  33.           {   
  34.            break;
  35.           }
  36.          cout<<"是否繼續購買(1)yes(2)No"<<endl;
  37.          cin>>number;
  38.          if(number==1)
  39.          {
  40.            continue;
  41.          }
  42.          else
  43.          {
  44.          buy[index]=a;
  45.     cout<<"數量:"<<endl;
  46.     cin>>z;
  47.     buycount[index]=z;
  48.     w= w+n[a-1]*z;
  49.     index++;
  50.     }
  51.    }
  52.     cout<<"商品金額"<<endl;
  53.     cout<<"------------------------"<<endl;
  54.     for(int i=0;i<index;i++)
  55.     {
  56.        cout<<num[buy[i]-1]<<"\t"<<n[buy[i]-1]<<"元"<<buycount[i]<<"個"<<endl;     
  57.     }
  58.      cout<<"------------------------"<<endl;
  59.     cout<<"總金額:"<<w<<endl;

  60.    }
  61.     system("pause");
  62.      return 0;     
  63. }
複製代碼

TOP

返回列表