Board logo

標題: 抽籤程式 [打印本頁]

作者: 陳品肇    時間: 2019-3-30 13:16     標題: 抽籤程式

本帖最後由 陳品肇 於 2019-3-30 14:14 編輯

發揮創意想想看, 抽籤程式在日生活中甚麼時候可以派上用場呢?
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n ;
  7.     string name[5]={"雞排","便當","麵","粥","火鍋"};
  8.     cout<<"☆★☆抽籤程式☆★☆"<<endl;
  9.     cout<<"今晚你要吃什麼?"<<endl;
  10.     system("pause");  //畫面停留
  11.     system("cls"); //畫面清空  
  12.     srand(time(NULL));
  13.    
  14.     for(int i=1;i<=100;i++)  //做出跑馬燈的效果
  15.     {
  16.         //產生0~4
  17.        n = rand()%5;
  18.        if(i%2==0)
  19.        {
  20.            cout<<"☆★☆抽籤中☆★☆"<<endl;
  21.        }else
  22.        {
  23.            cout<<"★☆★抽籤中★☆★"<<endl;
  24.        }
  25.        cout<<name[n]<<endl;  //印出食物名稱
  26.        system("cls"); //畫面清空
  27.     }
  28.    
  29.    
  30.     cout<<"今晚選重的食物是:"<<name[n]<<endl;  //印出食物名稱
  31.    
  32.     system("pause");
  33.     return 0;
  34. }
複製代碼

作者: 吳孟修    時間: 2019-3-30 14:24

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x;
  7.     string n[]={"飯","麵","粥","漢堡","火鍋"};
  8.     cout<<"☆★☆抽籤程式☆★☆"<<endl;
  9.     cout<<"今晚你要吃什麼?\n"<<endl;
  10.     system("pause");
  11.     system("cls");
  12.     srand(time(NULL));
  13.     for(int i=1;i<=150;i++)
  14.     {
  15.         x=rand()%5;
  16.         if(i%2==0)
  17.         {
  18.             cout<<"☆★☆抽籤中☆★☆"<<endl;
  19.         }
  20.         else
  21.         {
  22.             cout<<"★☆★抽籤中★☆★"<<endl;   
  23.         }
  24.         cout<<n[x]<<endl;
  25.         system("cls");            
  26.     }
  27.     cout<<"今晚選中的食物是:"<<n[x]<<endl;
  28.     system("pause");
  29.     return 0;   
  30. }
複製代碼

作者: 章幼莛    時間: 2019-3-30 14:24

本帖最後由 章幼莛 於 2019-3-30 14:27 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     cout<<"☆★☆抽籤程式☆★☆"<<endl;
  8.     cout<<"今晚吃什麼?"<<endl;
  9.     string food[5]={"炒飯","炒麵","意麵","煎餃","滷味"};
  10.     system("pause");
  11.     system("cls");
  12.     srand(time(NULL));
  13.     for(int i=1;i<=100;i++)
  14.     {
  15.             a=rand()%5;
  16.             if(i%2==0)
  17.             {
  18.                  cout<<"☆★☆抽籤中☆★☆"<<endl;
  19.             }else
  20.             {
  21.                  cout<<"★☆★抽籤中★☆★"<<endl;
  22.             }
  23.             cout<<food[a]<<endl;
  24.             system("cls");
  25.     }
  26.     cout<<"今天晚上選的食物是:"<<food[a]<<endl;
  27.     system("pause");
  28.     return 0;   
  29. }
複製代碼

作者: 田宇任    時間: 2019-3-30 14:25

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {

  6.     int n;
  7.     string name[5]={"香蕉","鳳梨","西瓜","蘋果","蓮霧"};
  8.    
  9.     cout<<"★☆★抽籤程式★☆★"<<endl;
  10.     cout<<"吃什麼水果?"<<endl;
  11.     system("pause");
  12.     system("cls");
  13.    
  14.     srand(time(NULL));
  15.    
  16.     for(int i=1;i<=120;i++)
  17.     {
  18.             n = rand()%5;
  19.      if(i%2==0)
  20.      {
  21.       cout<<"☆★☆為您決定中...☆★☆"<<endl;
  22.      }else
  23.      {
  24.       cout<<"★☆★為您決定中...★☆★"<<endl;
  25.      }
  26.      cout<<name[n]<<endl;
  27.      system("cls");
  28.     }
  29.    
  30.     cout<<"吃:"<<name[n]<<endl<<endl;
  31.    
  32.    
  33.     system("pause");
  34.     return 0;
  35. }
複製代碼

作者: 吳孟書    時間: 2019-3-30 14:30

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n;
  7.     string d[5]={"飯","麵","粥","漢堡","火鍋"};
  8.     srand(time(NULL));
  9.     cout<<"☆★☆抽籤程式☆★☆"<<endl;
  10.     cout<<"今晚要吃什麼?(按Enter鍵開始抽籤)"<<endl;
  11.     system("pause");
  12.     system("cls");
  13.     for(int i=0;i<=150;i++)
  14.     {
  15.          n=rand()%5;
  16.          if(i%2==0)
  17.          {
  18.               cout<<"☆★☆抽籤中☆★☆"<<endl;
  19.          }
  20.          else
  21.          {
  22.               cout<<"★☆★抽籤中★☆★"<<endl;
  23.          }
  24.          cout<<d[n]<<endl;
  25.          system("cls");
  26.     }
  27.     cout<<"今晚吃"<<d[n]<<"!"<<endl;
  28.     system("pause");
  29.     return 0;   
  30. }
複製代碼

作者: 曲書辰    時間: 2019-3-30 14:34

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n;
  7.     string f[]={"湯","飯","肉","麵","菜","水果"};
  8.     cout<<"☆★☆抽籤程式☆★☆"<<endl;
  9.     cout<<"今晚你要吃什麼"<<endl;
  10.     system("cls");
  11.     srand(time(NULL));
  12.     for(int i=1;i<200;i++)
  13.     {

  14.      n=rand()%5;
  15.      if(i%2==0)
  16.      cout<<"☆★☆抽籤程式☆★☆"<<endl;
  17.      else
  18.      cout<<"★☆★抽籤中★☆★"<<endl;
  19.      cout<<f[n]<<endl;
  20.      system("cls");      
  21.     }
  22.     cout<<"☆★☆抽籤程式☆★☆"<<endl;
  23.     cout<<f[n]<<endl;
  24.    
  25.    
  26.    
  27.    
  28.    
  29.     system("pause");
  30.     return 0;   
  31.    
  32. }
複製代碼

作者: 洪寬瀧    時間: 2019-3-30 14:34

  1. #include<iostream>          //☆★◇◆□■▽▼㊣℅¯>﹤㏒
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. int h;
  7. string name[5]={"咖哩飯","煎餃","牛肉麵","炒飯","水餃"};
  8. cout<<"∴抽籤程式∴"<<endl;
  9. cout<<"≒今晚吃甚麼≒"<<endl;
  10.   system("pause");
  11.   system("cls");
  12.    
  13. srand(time(NULL));
  14.    for(int i=1;i<=300;i++)
  15.   {
  16.   h=rand()%5;
  17.   if(i%2==0)
  18.        {
  19.            cout<<"☆★☆抽籤中☆★☆"<<endl;
  20.        }else
  21.        {
  22.            cout<<"★☆★抽籤中★☆★"<<endl;
  23.        }
  24.        cout<<name[h]<<endl;
  25.        system("cls");  
  26.   }
  27.   

  28.     cout<<"今晚選中的食物是:"<<name[h]<<endl;


  29.   system("pause");
  30. return 0;
  31. }   
複製代碼

作者: 王瑞喻    時間: 2019-3-30 14:50

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n;
  7.     string name[5]={"白色","紅色","黃色","綠色","紫色"};
  8.     cout<<"☆★☆抽籤程式☆★☆"<<endl;
  9.     cout<<"今天穿甚麼顏色?"<<endl;
  10.     system("pause");//畫面暫停
  11.     system("cls"); //畫面清空
  12.     srand(time(NULL));
  13.     for(int i=1;i<=100;i++)
  14.     {
  15.         n=rand()%5;
  16.         if(i%2==0)
  17.         {
  18.            cout<<"☆★☆抽籤中☆★☆"<<endl;
  19.         }else
  20.         {
  21.             cout<<"★☆★抽籤中★☆★"<<endl;
  22.         }
  23.    
  24.     cout<<name[n]<<endl;
  25.     system("cls");
  26.     }
  27.     cout<<"今天要穿的顏色是:"<<name[n]<<endl;
  28.     system("pause");
  29.     return 0;
  30. }
複製代碼

作者: 蘇昱全    時間: 2019-4-6 11:56

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string n[5]={"齊爾","甲蟲","悟空","兔子","瑟斐斯"};
  7.     srand(time(NULL));
  8.     cout<<"☆★☆抽籤程式☆★☆"<<endl;
  9.     cout<<"今天你要玩什麼角色?"<<endl;
  10.     system("pause");  
  11.     system("cls");   
  12.       
  13.    
  14.     for(int i=1;i<=50;i++)  
  15.     {
  16.        if(i%2==1)
  17.        {
  18.            cout<<"☆★☆抽籤中☆★☆"<<endl;
  19.        }else
  20.        {
  21.            cout<<"★☆★抽籤中★☆★"<<endl;
  22.            cout<<"是:"<<n[rand()%5]<<endl;
  23.        }
  24.       if(i<30)
  25.         _sleep(50);
  26.       else
  27.         _sleep(50+(i-30)*(i-30));
  28.         system("cls");
  29.     }
  30.     cout<<"選中的角色是:"<<n[rand()%5]<<endl;   
  31.    
  32.     system("pause");
  33.     return 0;
  34. }
複製代碼

作者: 湯郡一    時間: 2019-4-6 11:56

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string n[]={"漢堡","三明治","炒飯","吐司夾蛋","披薩"};
  7.     srand(time(NULL));
  8.     cout<<"☆★☆抽籤程式☆★☆"<<endl;
  9.     cout<<"今天中午要吃什麼?"<<endl;
  10.     system("pause");  
  11.     system("cls");
  12.     for(int i=1;i<=50;i++)
  13.     {
  14.          if(i%2==1)
  15.              cout<<"☆★☆抽籤中☆★☆"<<endl;
  16.          else
  17.              cout<<"☆★☆抽籤中☆★☆"<<endl;
  18.              cout<<"吃"<<n[rand()%5]<<endl;
  19.              if(i<30)
  20.                  _sleep(20);
  21.              else
  22.                  _sleep(20+(i-30)*(i-30));   
  23.          system("cls");           
  24.     }
  25.     cout<<"吃:"<<n[rand()%5]<<endl;
  26.     system("pause");
  27.     return 0;   
  28. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2