延續 抽籤程式 (一) 的練習,使在接近顯示抽籤結果時,洗牌的速度漸漸慢下來。
抽籤程式v2.exe- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- string food[]={"漢堡","牛排","羊肉爐","意麵","大便","餿水"};
- srand(time(NULL));
- re:
- system("cls");
- cout<<"☆★☆ 抽籤程式 ☆★☆"<<endl;
- cout<<"今天晚餐\吃什麼?"<<endl<<endl;
- system("pause");
- for(int i=1; i<=52; i++)
- {
- if(i%2==1)
- cout<<"★☆★ 抽籤中 ★☆★"<<endl;
- else
- cout<<"☆★☆ 抽籤中 ☆★☆"<<endl;
- cout<<food[rand()%6]<<"!"<<endl;
- if(i<=30)
- _sleep(20);
- else
- _sleep(20+(i-30)*(i-30));
- system("cls");
- }
- cout<<"吃: "<<food[rand()%6]<<"!"<<endl<<endl;
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |