返回列表 發帖

[隨堂測驗] 抽籤程式

本帖最後由 周政輝 於 2018-4-28 13:50 編輯

發揮創意想想看, 抽籤程式在日生活中甚麼時候可以派上用場呢?
給定一個食物的陣列,裡面的內容物有10樣食物可以吃
請隨機產生一個作為今天晚餐的內容
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     srand(time(NULL));
  8.     int food=0;
  9.     cout<<"今天晚上吃啥"<<endl;
  10.     string a[]={"雞肉","牛排","漢堡","豬腳","義大利麵","鵝肉","鴨肉","法國土司","薯條","炸雞"};
  11.     food=(rand()%9)+1;
  12.     cout << "今天吃:" << a[food-1] << endl;
  13.     system("pause");
  14.     return 0;
  15. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     srand(time(NULL));
  8.     int food=0;
  9.     cout<<"抽籤中"<<endl;
  10.     cout<<"========="<<endl;
  11.     cout<<"今晚吃啥?"<<endl;
  12.     string mora[]={"麵","牛肉","漢堡","披薩","炸雞","牛肉飯","奶昔","鵝肉","吐司","豬腳麵"};
  13.     food=(rand()%10)+1;
  14.     cout <<"吃:"<<mora[food-1]<<endl;
  15.     system("pause");
  16.     return 0;     
  17. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     cout<<"☆★☆抽籤程式☆★☆"<<endl;
  8.     int food=0;
  9.     string a []={
  10.     "豬肉","雞肉","牛肉",
  11.     "鴨肉","鵝肉","羊肉",
  12.     "漢堡","秋刀魚","鰻魚",
  13.     "鮭魚"};
  14.     srand(time(NULL));           
  15.     food=(rand()%10-1)+1;
  16.     cout<<"今晚吃啥"<<endl;   
  17.     cout << "今天吃:" << a[food-1] << endl;
  18.     system("pause");   
  19.     return 0;
  20. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     srand(time(NULL));
  8.     int supper=0;
  9.     string food[]={"米飯",
  10.                    "麵包",
  11.                    "蛋糕","餅乾","饅頭","麵條","玉米","蕃薯","芋頭","糖果"};
  12.     supper=(rand()%(10-1+1)+1);
  13.     cout<<"吃"<<food[supper+1]<<endl;
  14.     system("pause");
  15.     return 0;
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<time.h>
  4. using namespace std;
  5. int main()
  6. {         
  7.     int num = 0;
  8.     cout<<"☆★☆抽籤程式☆★☆"<<endl;
  9.     cout<<"===================="<<endl;
  10.     cout<<"★今天晚上要吃什麼★"<<endl;      
  11.     string j[]=
  12.     {
  13.         "豬肉",
  14.         "牛肉",
  15.         "雞肉",
  16.         "羊肉",
  17.         "鴨肉",
  18.         "泡麵",
  19.         "漢堡",
  20.         "薯條",
  21.         "雞塊",
  22.         "餅乾",
  23.     };
  24.     srand(time(NULL));
  25.     num=(rand()%10)+1;
  26.     cout<<endl;
  27.     cout<<"~今天晚上吃"<<j[num-1]<<"好了~"<<endl;
  28.     cout<<endl;
  29.     system("pause");
  30.     return 0;   
  31. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. srand(time(NULL));
  7.    int food =0;  
  8.       cout<<"今天晚餐吃"<<endl;
  9.      string mora[] = {"吃今天晚餐: (1:雞,豬,牛,鵝,漢堡,羊,飯,麵,吐司,豬腳,)"};
  10.      food=(rand()%9)+1;
  11.     cout << "今天晚餐吃" << endl;
  12.    system("pause");
  13.    return 0;   
  14. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     cout << "生" << endl;
  7.     _sleep(300);
  8.     system("cls");
  9.     cout << "  日" << endl;
  10.     _sleep(300);
  11.     system("cls");
  12.     cout << "    快" << endl;
  13.     _sleep(300);
  14.     system("cls");
  15.     cout << "      樂" << endl;
  16.     _sleep(300);
  17.     system("cls");
  18.     cout << "生日快樂" << endl;
  19.     _sleep(300);
  20.     system("cls");
  21.     system("pause");
  22.     return 0;
  23. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string food[]={"漢堡","牛排","羊肉爐","意麵","大便","餿水"};
  7.     srand(time(NULL));
  8.     while(true)
  9.     {
  10.     cout<<"☆★☆抽籤程式☆★☆"<<endl;
  11.     cout<<"今晚吃甚麼?"<<endl;
  12.     system("pause");
  13.     system("cls");
  14.     for(int i=1;i<=30;i++)
  15.     {
  16.             if(i%2!=0)
  17.             {
  18.                       cout<<"☆★☆抽籤中☆★☆"<<endl;
  19.                       cout<<food[rand()%6]<<"!";
  20.             }
  21.             if(i%2==0)
  22.             {
  23.                       cout<<"★☆★抽籤中★☆★"<<endl;
  24.                       cout<<food[rand()%6]<<"!";
  25.             }
  26.             _sleep(55+i);
  27.             system("cls");
  28.     }
  29.     cout<<"吃"<<food[rand()%6]<<"!"<<endl;
  30.     system("pause");
  31.     }
  32.     system("pause");   
  33.     return 0;
  34. }
複製代碼

TOP

返回列表